Skip to content
PHP Ecosystem
Explore

SqlToken

API reference › yii › db › SqlToken

classyii\db\SqlToken
Extendsyii\base\BaseObject
ImplementsArrayAccess, yii\base\Configurable
Since2.0.13
Sourceframework/db/SqlToken.php

SqlToken represents SQL tokens produced by SqlTokenizer or its child classes.

PropertyTypeDescriptionDefined by
$childrenSqlToken[]Child tokens.SqlToken
$contentstring|nullToken content. Default: null.SqlToken
$endOffsetintOriginal SQL token end position. Default: null.SqlToken
$hasChildren read-onlyboolWhether the token has children.SqlToken
$isCollection read-onlyboolWhether the token represents a collection of tokens.SqlToken
$parentSqlTokenParent token. Default: null.SqlToken
$sql read-onlystringSQL code.SqlToken
$startOffsetintOriginal SQL token start position. Default: null.SqlToken
$typeintToken type. Default: self::TYPE_TOKEN.SqlToken
MethodDescriptionDefined by
__construct()Constructor.yii\base\BaseObject
__call()Calls the named method which is not a class method.yii\base\BaseObject
__get()Returns the value of an object property.yii\base\BaseObject
__isset()Checks if a property is set, i.e. defined and not null.yii\base\BaseObject
__set()Sets value of an object property.yii\base\BaseObject
__toString()Returns the SQL code representing the token.SqlToken
__unset()Sets an object property to null.yii\base\BaseObject
canGetProperty()Returns a value indicating whether a property can be read.yii\base\BaseObject
canSetProperty()Returns a value indicating whether a property can be set.yii\base\BaseObject
className() staticReturns the fully qualified name of this class.yii\base\BaseObject
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\base\BaseObject
hasProperty()Returns a value indicating whether a property is defined.yii\base\BaseObject
init()Initializes the object.yii\base\BaseObject
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
ConstantValueDescriptionDefined by
TYPE_CODE0SqlToken
TYPE_STATEMENT1SqlToken
TYPE_TOKEN2SqlToken
TYPE_PARENTHESIS3SqlToken
TYPE_KEYWORD4SqlToken
TYPE_OPERATOR5SqlToken
TYPE_IDENTIFIER6SqlToken
TYPE_STRING_LITERAL7SqlToken
public int $type = self::TYPE_TOKEN

Token type.

It has to be one of the following constants:

public function __toString(): string

Returns the SQL code representing the token.

Returns

string: SQL code.

public function getChildren(): yii\db\SqlToken[]

Returns child tokens.

Returns

SqlToken[]: Child tokens.

public function getHasChildren(): bool

Returns whether the token represents a collection of tokens and has non-zero number of children.

Returns

bool: Whether the token has children.

public function getIsCollection(): bool

Returns whether the token represents a collection of tokens.

Returns

bool: Whether the token represents a collection of tokens.

public function getSql(): string

Returns the SQL code representing the token.

Returns

string: SQL code.

public function matches(yii\db\SqlToken $patternToken, int $offset = 0, int|null &$firstMatchIndex = null, int|null &$lastMatchIndex = null): bool

Returns 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

ParameterTypeDescription
$patternTokenSqlTokenTokenized SQL code to match against. In addition to normal SQL, the any keyword is supported which will match any number of keywords, identifiers, whitespaces.
$offsetintToken children offset to start lookup with.
$firstMatchIndexint|nullToken children offset where a successful match begins.
$lastMatchIndexint|nullToken children offset where a successful match ends.

Returns

bool: Whether this token matches the pattern SQL code.

public function offsetExists(int $offset): bool

Returns 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

ParameterTypeDescription
$offsetintChild token offset.

Returns

bool: Whether the token exists.

public function offsetGet(int $offset): yii\db\SqlToken|null

Returns 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

ParameterTypeDescription
$offsetintChild token offset.

Returns

SqlToken|null: The child token at the specified offset, null if there’s no token.

public function offsetSet(int|null $offset, yii\db\SqlToken $token): mixed

Adds 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

ParameterTypeDescription
$offsetint|nullChild token offset.
$tokenSqlTokenToken to be added.

Returns

mixed

public function offsetUnset(int $offset): mixed

Removes 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

ParameterTypeDescription
$offsetintChild token offset.

Returns

mixed

public function setChildren(yii\db\SqlToken[] $children): mixed

Sets a list of child tokens.

Parameters

ParameterTypeDescription
$childrenSqlToken[]Child tokens.

Returns

mixed