Abstract Class Yiisoft\Db\Syntax\AbstractSqlParser
| Inheritance | Yiisoft\Db\Syntax\AbstractSqlParser |
|---|
SQL parser.
This class provides methods to parse SQL statements and extract placeholders from them.
Protected Properties
| Property | Type | Description | Defined By |
|---|---|---|---|
| $length | integer | Length of SQL statement. | Yiisoft\Db\Syntax\AbstractSqlParser |
| $position | integer | Current position in SQL statement. | Yiisoft\Db\Syntax\AbstractSqlParser |
| $sql | string | Yiisoft\Db\Syntax\AbstractSqlParser |
Public Methods
| Method | Description | Defined By |
|---|---|---|
| __construct() | Yiisoft\Db\Syntax\AbstractSqlParser | |
| getNextPlaceholder() | Returns the next placeholder from the current position in an SQL statement. | Yiisoft\Db\Syntax\AbstractSqlParser |
Protected Methods
| Method | Description | Defined By |
|---|---|---|
| parseIdentifier() | Parses and returns identifier. Equivalent to [_a-zA-Z]\w* in regular expressions. |
Yiisoft\Db\Syntax\AbstractSqlParser |
| parseWord() | Parses and returns word characters. Equivalent to \w* in regular expressions. |
Yiisoft\Db\Syntax\AbstractSqlParser |
| skipChars() | Skips all specified characters. | Yiisoft\Db\Syntax\AbstractSqlParser |
| skipQuotedWithEscape() | Skips quoted string with escape characters. | Yiisoft\Db\Syntax\AbstractSqlParser |
| skipQuotedWithoutEscape() | Skips quoted string without escape characters. | Yiisoft\Db\Syntax\AbstractSqlParser |
| skipToAfterChar() | Skips to the character after the specified character. | Yiisoft\Db\Syntax\AbstractSqlParser |
| skipToAfterString() | Skips to the character after the specified string. | Yiisoft\Db\Syntax\AbstractSqlParser |
Constants
| Constant | Value | Description | Defined By |
|---|---|---|---|
| LETTER_CHARS | '_abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ' | Yiisoft\Db\Syntax\AbstractSqlParser | |
| WORD_CHARS | '0123456789' . self::LETTER_CHARS | Yiisoft\Db\Syntax\AbstractSqlParser |
Property Details
Method Details
| public __construct( string $sql ): mixed | ||
| $sql | string |
SQL statement to parse. |
public function __construct(protected string $sql)
{
$this->length = strlen($sql);
}
Returns the next placeholder from the current position in an SQL statement.
| public abstract getNextPlaceholder( integer|null &$position = null ): string|null | ||
| $position | integer|null |
Position of the placeholder in an SQL statement. |
| return | string|null |
The next placeholder or null if it is not found. |
|---|---|---|
abstract public function getNextPlaceholder(?int &$position = null): ?string;
Parses and returns identifier. Equivalent to [_a-zA-Z]\w* in regular expressions.
| protected parseIdentifier( ): string | ||
| return | string |
Parsed identifier. |
|---|---|---|
protected function parseIdentifier(): string
{
$length = strspn($this->sql, self::LETTER_CHARS, $this->position);
if ($length === 0) {
return '';
}
$length += strspn($this->sql, self::WORD_CHARS, $this->position + $length);
$word = substr($this->sql, $this->position, $length);
$this->position += $length;
return $word;
}
Parses and returns word characters. Equivalent to \w* in regular expressions.
| protected parseWord( ): string | ||
| return | string |
Parsed word characters. |
|---|---|---|
final protected function parseWord(): string
{
$length = strspn($this->sql, self::WORD_CHARS, $this->position);
$word = substr($this->sql, $this->position, $length);
$this->position += $length;
return $word;
}
Skips all specified characters.
| protected skipChars( string $char ): void | ||
| $char | string | |
final protected function skipChars(string $char): void
{
$length = strspn($this->sql, $char, $this->position);
$this->position += $length;
}
Skips quoted string with escape characters.
| protected skipQuotedWithEscape( string $endChar ): void | ||
| $endChar | string | |
final protected function skipQuotedWithEscape(string $endChar): void
{
preg_match("/(?>[^$endChar\\\\]+|\\\\.)*/", $this->sql, $matches, 0, $this->position);
$this->position += strlen($matches[0]) + 1;
}
Skips quoted string without escape characters.
| protected skipQuotedWithoutEscape( string $endChar ): void | ||
| $endChar | string | |
final protected function skipQuotedWithoutEscape(string $endChar): void
{
do {
$this->skipToAfterChar($endChar);
} while (($this->sql[$this->position] ?? null) === $endChar && ++$this->position);
}
Skips to the character after the specified character.
| protected skipToAfterChar( string $char ): void | ||
| $char | string | |
final protected function skipToAfterChar(string $char): void
{
$length = strcspn($this->sql, $char, $this->position);
$this->position += $length + 1;
}
Skips to the character after the specified string.
| protected skipToAfterString( string $string ): void | ||
| $string | string | |
final protected function skipToAfterString(string $string): void
{
/** @var int $pos */
$pos = strpos($this->sql, $string, $this->position);
$this->position = $pos + strlen($string);
}
Signup or Login in order to comment.