Class yii\db\SqlToken

Inheritanceyii\db\SqlToken » yii\base\BaseObject
ImplementsArrayAccess, yii\base\Configurable
Available since version2.0.13
Source Code https://github.com/yiisoft/yii2/blob/master/framework/db/SqlToken.php

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

Public Properties

Hide inherited properties

PropertyTypeDescriptionDefined By
$children yii\db\SqlToken[] Child tokens. yii\db\SqlToken
$content string|null Token content. yii\db\SqlToken
$endOffset integer Original SQL token end position. yii\db\SqlToken
$hasChildren boolean Whether the token has children. yii\db\SqlToken
$isCollection boolean Whether the token represents a collection of tokens. yii\db\SqlToken
$parent yii\db\SqlToken Parent token. yii\db\SqlToken
$sql string SQL code. yii\db\SqlToken
$startOffset integer Original SQL token start position. yii\db\SqlToken
$type integer Token type. yii\db\SqlToken

Public Methods

Hide inherited methods

MethodDescriptionDefined By
__call() Calls the named method which is not a class method. yii\base\BaseObject
__construct() Constructor. 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. yii\db\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() Returns the fully qualified name of this class. yii\base\BaseObject
getChildren() Returns child tokens. yii\db\SqlToken
getHasChildren() Returns whether the token represents a collection of tokens and has non-zero number of children. yii\db\SqlToken
getIsCollection() Returns whether the token represents a collection of tokens. yii\db\SqlToken
getSql() Returns the SQL code representing the token. yii\db\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. yii\db\SqlToken
offsetExists() yii\db\SqlToken
offsetGet() yii\db\SqlToken
offsetSet() yii\db\SqlToken
offsetUnset() yii\db\SqlToken
setChildren() Sets a list of child tokens. yii\db\SqlToken

Constants

Hide inherited constants

ConstantValueDescriptionDefined By
TYPE_CODE 0 yii\db\SqlToken
TYPE_IDENTIFIER 6 yii\db\SqlToken
TYPE_KEYWORD 4 yii\db\SqlToken
TYPE_OPERATOR 5 yii\db\SqlToken
TYPE_PARENTHESIS 3 yii\db\SqlToken
TYPE_STATEMENT 1 yii\db\SqlToken
TYPE_STRING_LITERAL 7 yii\db\SqlToken
TYPE_TOKEN 2 yii\db\SqlToken

Property Details

$children public property

Child tokens.

public yii\db\SqlToken[] $children null
$content public property

Token content.

public string|null $content null
$endOffset public property

Original SQL token end position.

public integer $endOffset null
$hasChildren public property

Whether the token has children.

public boolean $hasChildren null
$isCollection public property

Whether the token represents a collection of tokens.

public boolean $isCollection null
$parent public property

Parent token.

public yii\db\SqlToken $parent null
$sql public property

SQL code.

public string $sql null
$startOffset public property

Original SQL token start position.

public integer $startOffset null
$type public property
public integer $type self::TYPE_TOKEN

Method Details

__toString() public method

Returns the SQL code representing the token.

public string __toString ( )
return string

SQL code.

getChildren() public method

Returns child tokens.

public yii\db\SqlToken[] getChildren ( )
return yii\db\SqlToken[]

Child tokens.

getHasChildren() public method

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

public boolean getHasChildren ( )
return boolean

Whether the token has children.

getIsCollection() public method

Returns whether the token represents a collection of tokens.

public boolean getIsCollection ( )
return boolean

Whether the token represents a collection of tokens.

getSql() public method

Returns the SQL code representing the token.

public string getSql ( )
return string

SQL code.

matches() public method

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)) {
    // ...
}
public boolean matches ( yii\db\SqlToken $patternToken, $offset 0, &$firstMatchIndex null, &$lastMatchIndex null )
$patternToken yii\db\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 integer

Token children offset to start lookup with.

$firstMatchIndex integer|null

Token children offset where a successful match begins.

$lastMatchIndex integer|null

Token children offset where a successful match ends.

return boolean

Whether this token matches the pattern SQL code.

offsetExists() public method

public void offsetExists ( $offset )
$offset
offsetGet() public method

public void offsetGet ( $offset )
$offset
offsetSet() public method

public void offsetSet ( $offset, $token )
$offset
$token
offsetUnset() public method

public void offsetUnset ( $offset )
$offset
setChildren() public method

Sets a list of child tokens.

public void setChildren ( $children )
$children yii\db\SqlToken[]

Child tokens.