SQLParserUtils
in package
Utility class that parses sql statements with regard to types and parameters.
Tags
Table of Contents
- ESCAPED_BACKTICK_QUOTED_TEXT = '(?:`(?:\\\\)+`|`(?:[^`\\]|\\`?)*`)'
- ESCAPED_BRACKET_QUOTED_TEXT = '(?<!\bARRAY)\[(?:[^\]])*\]'
- ESCAPED_DOUBLE_QUOTED_TEXT = '(?:"(?:\\\\)+"|"(?:[^"\\]|\\"?)*")'
- ESCAPED_SINGLE_QUOTED_TEXT = "(?:'(?:\\\\)+'|'(?:[^'\\]|\\'?|'')*')"
- NAMED_TOKEN = '(?<!:):[a-zA-Z_][a-zA-Z0-9_]*'
- POSITIONAL_TOKEN = '\?'
- expandListParameters() : array<string|int, mixed>
- For a positional query this method can rewrite the sql statement with regard to array parameters.
- getPlaceholderPositions() : array<string|int, mixed>
- Gets an array of the placeholders in an sql statements as keys and their positions in the query string.
- extractParam() : mixed
- getUnquotedStatementFragments() : array<string|int, mixed>
- Slice the SQL statement around pairs of quotes and return string fragments of SQL outside of quoted literals.
Constants
ESCAPED_BACKTICK_QUOTED_TEXT
public
mixed
ESCAPED_BACKTICK_QUOTED_TEXT
= '(?:`(?:\\\\)+`|`(?:[^`\\]|\\`?)*`)'
ESCAPED_BRACKET_QUOTED_TEXT
public
mixed
ESCAPED_BRACKET_QUOTED_TEXT
= '(?<!\bARRAY)\[(?:[^\]])*\]'
ESCAPED_DOUBLE_QUOTED_TEXT
public
mixed
ESCAPED_DOUBLE_QUOTED_TEXT
= '(?:"(?:\\\\)+"|"(?:[^"\\]|\\"?)*")'
ESCAPED_SINGLE_QUOTED_TEXT
public
mixed
ESCAPED_SINGLE_QUOTED_TEXT
= "(?:'(?:\\\\)+'|'(?:[^'\\]|\\'?|'')*')"
NAMED_TOKEN
public
mixed
NAMED_TOKEN
= '(?<!:):[a-zA-Z_][a-zA-Z0-9_]*'
POSITIONAL_TOKEN
public
mixed
POSITIONAL_TOKEN
= '\?'
Methods
expandListParameters()
For a positional query this method can rewrite the sql statement with regard to array parameters.
public
static expandListParameters(string $query, array<string|int, mixed> $params, array<string|int, mixed> $types) : array<string|int, mixed>
Parameters
- $query : string
-
The SQL query to execute.
- $params : array<string|int, mixed>
-
The parameters to bind to the query.
- $types : array<string|int, mixed>
-
The types the previous parameters are in.
Tags
Return values
array<string|int, mixed> —getPlaceholderPositions()
Gets an array of the placeholders in an sql statements as keys and their positions in the query string.
public
static getPlaceholderPositions(string $statement[, bool $isPositional = true ]) : array<string|int, mixed>
Returns an integer => integer pair (indexed from zero) for a positional statement and a string => int[] pair for a named statement.
Parameters
- $statement : string
- $isPositional : bool = true
Return values
array<string|int, mixed> —extractParam()
private
static extractParam(string $paramName, array<string|int, mixed> $paramsOrTypes, bool $isParam[, mixed $defaultValue = null ]) : mixed
Parameters
- $paramName : string
-
The name of the parameter (without a colon in front)
- $paramsOrTypes : array<string|int, mixed>
-
A hash of parameters or types
- $isParam : bool
- $defaultValue : mixed = null
-
An optional default value. If omitted, an exception is thrown
Tags
Return values
mixed —getUnquotedStatementFragments()
Slice the SQL statement around pairs of quotes and return string fragments of SQL outside of quoted literals.
private
static getUnquotedStatementFragments(string $statement) : array<string|int, mixed>
Each fragment is captured as a 2-element array:
0 => matched fragment string, 1 => offset of fragment in $statement
Parameters
- $statement : string