Final Class Yiisoft\Db\Mysql\DQLQueryBuilder
| Inheritance | Yiisoft\Db\Mysql\DQLQueryBuilder » Yiisoft\Db\QueryBuilder\AbstractDQLQueryBuilder |
|---|
Implements a DQL (Data Query Language) SQL statements for MySQL, MariaDB.
Public Methods
| Method | Description | Defined By |
|---|---|---|
| buildLimit() | Yiisoft\Db\Mysql\DQLQueryBuilder |
Protected Methods
| Method | Description | Defined By |
|---|---|---|
| defaultExpressionBuilders() | Yiisoft\Db\Mysql\DQLQueryBuilder | |
| hasLimit() | Checks to see if the given limit is effective. | Yiisoft\Db\Mysql\DQLQueryBuilder |
| hasOffset() | Checks to see if the given offset is effective. | Yiisoft\Db\Mysql\DQLQueryBuilder |
Method Details
| public string buildLimit ( \Yiisoft\Db\Expression\ExpressionInterface|integer|null $limit, \Yiisoft\Db\Expression\ExpressionInterface|integer|null $offset ) | ||
| $limit | \Yiisoft\Db\Expression\ExpressionInterface|integer|null | |
| $offset | \Yiisoft\Db\Expression\ExpressionInterface|integer|null | |
public function buildLimit(ExpressionInterface|int|null $limit, ExpressionInterface|int|null $offset): string
{
$sql = '';
if ($this->hasLimit($limit)) {
$sql = 'LIMIT ' . ($limit instanceof ExpressionInterface ? $this->buildExpression($limit) : (string) $limit);
if ($this->hasOffset($offset)) {
$sql .= ' OFFSET ' . ($offset instanceof ExpressionInterface ? $this->buildExpression($offset) : (string) $offset);
}
} elseif ($this->hasOffset($offset)) {
/**
* Limit isn't optional in MySQL.
*
* @link https://stackoverflow.com/a/271650/1106908
* @link https://dev.mysql.com/doc/refman/5.0/en/select.html#idm47619502796240
*/
$sql = 'LIMIT '
. ($offset instanceof ExpressionInterface ? $this->buildExpression($offset) : (string) $offset)
. ', 18446744073709551615'; // 2^64-1
}
return $sql;
}
| protected array defaultExpressionBuilders ( ) |
protected function defaultExpressionBuilders(): array
{
return [
...parent::defaultExpressionBuilders(),
JsonOverlaps::class => JsonOverlapsBuilder::class,
Like::class => LikeBuilder::class,
NotLike::class => LikeBuilder::class,
ArrayMerge::class => ArrayMergeBuilder::class,
Longest::class => LongestBuilder::class,
Shortest::class => ShortestBuilder::class,
];
}
Checks to see if the given limit is effective.
| protected boolean hasLimit ( mixed $limit ) | ||
| $limit | mixed |
The given limit. |
| return | boolean |
Whether the limit is effective. |
|---|---|---|
protected function hasLimit(mixed $limit): bool
{
/** In MySQL limit argument must be a non-negative integer constant */
return ctype_digit((string) $limit);
}
Checks to see if the given offset is effective.
| protected boolean hasOffset ( mixed $offset ) | ||
| $offset | mixed |
The given offset. |
| return | boolean |
Whether the offset is effective. |
|---|---|---|
protected function hasOffset(mixed $offset): bool
{
/** In MySQL offset argument must be a non-negative integer constant */
$offset = (string) $offset;
return ctype_digit($offset) && $offset !== '0';
}
Signup or Login in order to comment.