SqlToken
API reference › yii › db › SqlToken
SqlToken represents SQL tokens produced by SqlTokenizer or its child classes.
Properties
Section titled “Properties”| Property | Type | Description | Defined by |
|---|---|---|---|
$children | SqlToken[] | Child tokens. | SqlToken |
$content | string| | Token content. Default: null. | SqlToken |
$endOffset | int | Original SQL token end position. Default: null. | SqlToken |
$hasChildren read-only | bool | Whether the token has children. | SqlToken |
$isCollection read-only | bool | Whether the token represents a collection of tokens. | SqlToken |
$parent | SqlToken | Parent token. Default: null. | SqlToken |
$sql read-only | string | SQL code. | SqlToken |
$startOffset | int | Original SQL token start position. Default: null. | SqlToken |
$type | int | Token type. Default: self::TYPE_TOKEN. | SqlToken |
Methods
Section titled “Methods”| Method | Description | Defined by |
|---|---|---|
__construct() | Constructor. | yii\ |
__call() | Calls the named method which is not a class method. | yii\ |
__get() | Returns the value of an object property. | yii\ |
__isset() | Checks if a property is set, i.e. defined and not null. | yii\ |
__set() | Sets value of an object property. | yii\ |
__toString() | Returns the SQL code representing the token. | SqlToken |
__unset() | Sets an object property to null. | yii\ |
canGetProperty() | Returns a value indicating whether a property can be read. | yii\ |
canSetProperty() | Returns a value indicating whether a property can be set. | yii\ |
className() static | Returns the fully qualified name of this class. | yii\ |
getChildren() | Returns child tokens. | SqlToken |
getHasChildren() | Returns whether the token represents a collection of tokens and has non-zero number of children. | SqlToken |
getIsCollection() | Returns whether the token represents a collection of tokens. | SqlToken |
getSql() | Returns the SQL code representing the token. | SqlToken |
hasMethod() | Returns a value indicating whether a method is defined. | yii\ |
hasProperty() | Returns a value indicating whether a property is defined. | yii\ |
init() | Initializes the object. | yii\ |
matches() | Returns whether this token (including its children) matches the specified “pattern” SQL code. | SqlToken |
offsetExists() | Returns whether there is a child token at the specified offset. | SqlToken |
offsetGet() | Returns a child token at the specified offset. | SqlToken |
offsetSet() | Adds a child token to the token. | SqlToken |
offsetUnset() | Removes a child token at the specified offset. | SqlToken |
setChildren() | Sets a list of child tokens. | SqlToken |
Constants
Section titled “Constants”| Constant | Value | Description | Defined by |
|---|---|---|---|
TYPE_CODE | 0 | SqlToken | |
TYPE_STATEMENT | 1 | SqlToken | |
TYPE_TOKEN | 2 | SqlToken | |
TYPE_PARENTHESIS | 3 | SqlToken | |
TYPE_KEYWORD | 4 | SqlToken | |
TYPE_OPERATOR | 5 | SqlToken | |
TYPE_IDENTIFIER | 6 | SqlToken | |
TYPE_STRING_LITERAL | 7 | SqlToken |
Property details
Section titled “Property details”$type
Section titled “$type ”public int $type = self::TYPE_TOKENToken type.
It has to be one of the following constants:
Method details
Section titled “Method details”__toString()
Section titled “__toString() ”public function __toString(): stringReturns the SQL code representing the token.
Returns
string: SQL code.
getChildren()
Section titled “getChildren() ”public function getChildren(): yii\db\SqlToken[]Returns child tokens.
Returns
SqlToken[]: Child tokens.
getHasChildren()
Section titled “getHasChildren() ”public function getHasChildren(): boolReturns whether the token represents a collection of tokens and has non-zero number of children.
Returns
bool: Whether the token has children.
getIsCollection()
Section titled “getIsCollection() ”public function getIsCollection(): boolReturns whether the token represents a collection of tokens.
Returns
bool: Whether the token represents a collection of tokens.
getSql()
Section titled “getSql() ”public function getSql(): stringReturns the SQL code representing the token.
Returns
string: SQL code.
matches()
Section titled “matches() ”public function matches(yii\db\SqlToken $patternToken, int $offset = 0, int|null &$firstMatchIndex = null, int|null &$lastMatchIndex = null): boolReturns whether this token (including its children) matches the specified “pattern” SQL code.
Usage Example:
$patternToken = (new \yii\db\sqlite\SqlTokenizer('SELECT any FROM any'))->tokenize();if ($sqlToken->matches($patternToken, 0, $firstMatchIndex, $lastMatchIndex)) { // ...}Parameters
| Parameter | Type | Description |
|---|---|---|
$patternToken | SqlToken | Tokenized SQL code to match against. In addition to normal SQL, the any keyword is supported which will match any number of keywords, identifiers, whitespaces. |
$offset | int | Token children offset to start lookup with. |
$firstMatchIndex | int| | Token children offset where a successful match begins. |
$lastMatchIndex | int| | Token children offset where a successful match ends. |
Returns
bool: Whether this token matches the pattern SQL code.
offsetExists()
Section titled “offsetExists() ”public function offsetExists(int $offset): boolReturns whether there is a child token at the specified offset.
This method is required by the SPL ArrayAccess interface.
It is implicitly called when you use something like isset($token[$offset]).
Parameters
| Parameter | Type | Description |
|---|---|---|
$offset | int | Child token offset. |
Returns
bool: Whether the token exists.
offsetGet()
Section titled “offsetGet() ”public function offsetGet(int $offset): yii\db\SqlToken|nullReturns a child token at the specified offset.
This method is required by the SPL ArrayAccess interface.
It is implicitly called when you use something like $child = $token[$offset];.
Parameters
| Parameter | Type | Description |
|---|---|---|
$offset | int | Child token offset. |
Returns
SqlToken|null: The child token at the specified offset, null if there’s no token.
offsetSet()
Section titled “offsetSet() ”public function offsetSet(int|null $offset, yii\db\SqlToken $token): mixedAdds a child token to the token.
This method is required by the SPL ArrayAccess interface.
It is implicitly called when you use something like $token[$offset] = $child;.
Parameters
| Parameter | Type | Description |
|---|---|---|
$offset | int| | Child token offset. |
$token | SqlToken | Token to be added. |
Returns
mixed
offsetUnset()
Section titled “offsetUnset() ”public function offsetUnset(int $offset): mixedRemoves a child token at the specified offset.
This method is required by the SPL ArrayAccess interface.
It is implicitly called when you use something like unset($token[$offset]).
Parameters
| Parameter | Type | Description |
|---|---|---|
$offset | int | Child token offset. |
Returns
mixed
setChildren()
Section titled “setChildren() ”public function setChildren(yii\db\SqlToken[] $children): mixedSets a list of child tokens.