Context
final class Context (View source)
Defines a context class that is later extended to define other contexts.
A context is a collection of keywords, operators and functions used for parsing.
Holds the configuration of the context that is currently used.
Constants
KEYWORD_MAX_LENGTH |
The maximum length of a keyword. |
LABEL_MAX_LENGTH |
The maximum length of a label. Ref: https://dev.mysql.com/doc/refman/5.7/en/statement-labels.html |
OPERATOR_MAX_LENGTH |
The maximum length of an operator. |
private CONTEXT_PREFIX |
The prefix concatenated to the context name when an incomplete class name
is specified. |
private OPERATORS |
List of operators and their flags. |
SQL_MODE_NONE |
|
SQL_MODE_ALLOW_INVALID_DATES |
|
SQL_MODE_ANSI_QUOTES |
|
SQL_MODE_COMPAT_MYSQL |
Compatibility mode for Microsoft's SQL server. This is the equivalent of {SQL_MODE_ANSI_QUOTES}. |
SQL_MODE_ERROR_FOR_DIVISION_BY_ZERO |
|
SQL_MODE_HIGH_NOT_PRECEDENCE |
|
SQL_MODE_IGNORE_SPACE |
|
SQL_MODE_NO_AUTO_CREATE_USER |
|
SQL_MODE_NO_AUTO_VALUE_ON_ZERO |
|
SQL_MODE_NO_BACKSLASH_ESCAPES |
|
SQL_MODE_NO_DIR_IN_CREATE |
|
SQL_MODE_NO_ENGINE_SUBSTITUTION |
|
SQL_MODE_NO_FIELD_OPTIONS |
|
SQL_MODE_NO_KEY_OPTIONS |
|
SQL_MODE_NO_TABLE_OPTIONS |
|
SQL_MODE_NO_UNSIGNED_SUBTRACTION |
|
SQL_MODE_NO_ZERO_DATE |
|
SQL_MODE_NO_ZERO_IN_DATE |
|
SQL_MODE_ONLY_FULL_GROUP_BY |
|
SQL_MODE_PIPES_AS_CONCAT |
|
SQL_MODE_REAL_AS_FLOAT |
|
SQL_MODE_STRICT_ALL_TABLES |
|
SQL_MODE_STRICT_TRANS_TABLES |
|
SQL_MODE_NO_ENCLOSING_QUOTES |
Custom mode. The table and column names and any other field that must be escaped will not be. Reserved keywords are being escaped regardless this mode is used or not. |
SQL_MODE_ANSI |
Equivalent to {SQL_MODE_REAL_AS_FLOAT}, {SQL_MODE_PIPES_AS_CONCAT}, {SQL_MODE_ANSI_QUOTES},
{@see SQL_MODE_IGNORE_SPACE}. |
SQL_MODE_DB2 |
Equivalent to {SQL_MODE_PIPES_AS_CONCAT}, {SQL_MODE_ANSI_QUOTES}, {SQL_MODE_IGNORE_SPACE},
{@see SQL_MODE_NO_KEY_OPTIONS}, {SQL_MODE_NO_TABLE_OPTIONS}, {SQL_MODE_NO_FIELD_OPTIONS}. |
SQL_MODE_MAXDB |
Equivalent to {SQL_MODE_PIPES_AS_CONCAT}, {SQL_MODE_ANSI_QUOTES}, {SQL_MODE_IGNORE_SPACE},
{@see SQL_MODE_NO_KEY_OPTIONS}, {SQL_MODE_NO_TABLE_OPTIONS}, {SQL_MODE_NO_FIELD_OPTIONS},
{@see SQL_MODE_NO_AUTO_CREATE_USER}. |
SQL_MODE_MSSQL |
Equivalent to {SQL_MODE_PIPES_AS_CONCAT}, {SQL_MODE_ANSI_QUOTES}, {SQL_MODE_IGNORE_SPACE},
{@see SQL_MODE_NO_KEY_OPTIONS}, {SQL_MODE_NO_TABLE_OPTIONS}, {SQL_MODE_NO_FIELD_OPTIONS}. |
SQL_MODE_ORACLE |
Equivalent to {SQL_MODE_PIPES_AS_CONCAT}, {SQL_MODE_ANSI_QUOTES}, {SQL_MODE_IGNORE_SPACE},
{@see SQL_MODE_NO_KEY_OPTIONS}, {SQL_MODE_NO_TABLE_OPTIONS}, {SQL_MODE_NO_FIELD_OPTIONS},
{@see SQL_MODE_NO_AUTO_CREATE_USER}. |
SQL_MODE_POSTGRESQL |
Equivalent to {SQL_MODE_PIPES_AS_CONCAT}, {SQL_MODE_ANSI_QUOTES}, {SQL_MODE_IGNORE_SPACE},
{@see SQL_MODE_NO_KEY_OPTIONS}, {SQL_MODE_NO_TABLE_OPTIONS}, {SQL_MODE_NO_FIELD_OPTIONS}. |
SQL_MODE_TRADITIONAL |
Equivalent to {SQL_MODE_STRICT_TRANS_TABLES}, {SQL_MODE_STRICT_ALL_TABLES},
{@see SQL_MODE_NO_ZERO_IN_DATE}, {SQL_MODE_NO_ZERO_DATE}, {SQL_MODE_ERROR_FOR_DIVISION_BY_ZERO},
{@see SQL_MODE_NO_AUTO_CREATE_USER}. |
Properties
static string | $loadedContext | The name of the loaded context. |
|
static array<string,int> | $keywords | List of keywords. |
|
static int internal | $mode | The mode of the MySQL server that will be used in lexing, parsing and building the statements. |
Methods
Checks if the given string is a keyword.
Checks if the given string is an operator and returns the appropriate flag for the operator.
Checks if the given character is a whitespace.
Checks if the given string is the beginning of a whitespace.
Checks if the given string is a boolean value.
Checks if the given character can be a part of a number.
Checks if the given character is the beginning of a symbol. A symbol can be either a variable or a field name.
Checks if the given character is the beginning of a string.
Checks if the given character can be a separator for two lexeme.
Loads the specified context.
Loads the context with the closest version to the one specified.
Gets the SQL mode.
Sets the SQL mode.
Escapes the symbol by adding surrounding backticks.
Escapes the symbol by adding surrounding backticks.
Function verifies that given SQL Mode constant is currently set
Details
static int|null
isKeyword(string $string, bool $isReserved = false)
Checks if the given string is a keyword.
static int|null
isOperator(string $string)
Checks if the given string is an operator and returns the appropriate flag for the operator.
static bool
isWhitespace(string $character)
Checks if the given character is a whitespace.
static int|null
isComment(string $string, bool $end = false)
Checks if the given string is the beginning of a whitespace.
static bool
isBool(string $string)
Checks if the given string is a boolean value.
This actually check only for TRUE
and FALSE
because 1
or 0
are
actually numbers and are parsed by specific methods.
static bool
isNumber(string $string)
Checks if the given character can be a part of a number.
static int|null
isSymbol(string $character)
Checks if the given character is the beginning of a symbol. A symbol can be either a variable or a field name.
static int|null
isString(string $character)
Checks if the given character is the beginning of a string.
static bool
isSeparator(string $string)
Checks if the given character can be a separator for two lexeme.
static bool
load(string $context = '')
Loads the specified context.
Contexts may be used by accessing the context directly.
static string|null
loadClosest(string $context = '')
Loads the context with the closest version to the one specified.
The closest context is found by replacing last digits with zero until one is loaded successfully.
static int
getMode()
Gets the SQL mode.
static void
setMode(int|string $mode = self::SQL_MODE_NONE)
Sets the SQL mode.
static string
escape(string $str, string $quote = '`')
Escapes the symbol by adding surrounding backticks.
static array
escapeAll(array $strings)
Escapes the symbol by adding surrounding backticks.
static bool
hasMode(int|null $flag = null)
Function verifies that given SQL Mode constant is currently set