|
1
|
|
|
<?php |
|
2
|
|
|
|
|
3
|
|
|
declare(strict_types=1); |
|
4
|
|
|
|
|
5
|
|
|
namespace Yiisoft\Db\Mysql; |
|
6
|
|
|
|
|
7
|
|
|
use Yiisoft\Db\Expression\Expression; |
|
8
|
|
|
use Yiisoft\Db\Expression\ExpressionBuilder; |
|
9
|
|
|
use Yiisoft\Db\Expression\JsonExpression; |
|
10
|
|
|
use Yiisoft\Db\Mysql\Builder\JsonExpressionBuilder; |
|
11
|
|
|
use Yiisoft\Db\QueryBuilder\DQLQueryBuilder as AbstractDQLQueryBuilder; |
|
|
|
|
|
|
12
|
|
|
|
|
13
|
|
|
use function array_merge; |
|
14
|
|
|
use function ctype_digit; |
|
15
|
|
|
|
|
16
|
|
|
final class DQLQueryBuilder extends AbstractDQLQueryBuilder |
|
17
|
|
|
{ |
|
18
|
183 |
|
public function buildLimit(Expression|int|null $limit, Expression|int|null $offset): string |
|
19
|
|
|
{ |
|
20
|
183 |
|
$sql = ''; |
|
21
|
|
|
|
|
22
|
183 |
|
if ($this->hasLimit($limit)) { |
|
23
|
9 |
|
$sql = 'LIMIT ' . (string) $limit; |
|
24
|
|
|
|
|
25
|
9 |
|
if ($this->hasOffset($offset)) { |
|
26
|
9 |
|
$sql .= ' OFFSET ' . (string) $offset; |
|
27
|
|
|
} |
|
28
|
177 |
|
} elseif ($this->hasOffset($offset)) { |
|
29
|
|
|
/** |
|
30
|
|
|
* limit is not optional in MySQL. |
|
31
|
|
|
* |
|
32
|
|
|
* http://stackoverflow.com/a/271650/1106908 |
|
33
|
|
|
* http://dev.mysql.com/doc/refman/5.0/en/select.html#idm47619502796240 |
|
34
|
|
|
*/ |
|
35
|
|
|
$sql = "LIMIT $offset, 18446744073709551615"; // 2^64-1 |
|
36
|
|
|
} |
|
37
|
|
|
|
|
38
|
183 |
|
return $sql; |
|
39
|
|
|
} |
|
40
|
|
|
|
|
41
|
|
|
/** |
|
42
|
|
|
* Checks to see if the given limit is effective. |
|
43
|
|
|
* |
|
44
|
|
|
* @param mixed $limit the given limit. |
|
45
|
|
|
* |
|
46
|
|
|
* @return bool whether the limit is effective. |
|
47
|
|
|
*/ |
|
48
|
183 |
|
protected function hasLimit(mixed $limit): bool |
|
49
|
|
|
{ |
|
50
|
|
|
/** In MySQL limit argument must be non-negative integer constant */ |
|
51
|
183 |
|
return ctype_digit((string) $limit); |
|
52
|
|
|
} |
|
53
|
|
|
|
|
54
|
|
|
/** |
|
55
|
|
|
* Checks to see if the given offset is effective. |
|
56
|
|
|
* |
|
57
|
|
|
* @param mixed $offset the given offset. |
|
58
|
|
|
* |
|
59
|
|
|
* @return bool whether the offset is effective. |
|
60
|
|
|
*/ |
|
61
|
183 |
|
protected function hasOffset(mixed $offset): bool |
|
62
|
|
|
{ |
|
63
|
|
|
/** In MySQL offset argument must be non-negative integer constant */ |
|
64
|
183 |
|
$offset = (string) $offset; |
|
65
|
183 |
|
return ctype_digit($offset) && $offset !== '0'; |
|
66
|
|
|
} |
|
67
|
|
|
|
|
68
|
|
|
/** |
|
69
|
|
|
* Contains array of default expression builders. Extend this method and override it, if you want to change default |
|
70
|
|
|
* expression builders for this query builder. |
|
71
|
|
|
* |
|
72
|
|
|
* See {@see ExpressionBuilder} docs for details. |
|
73
|
|
|
*/ |
|
74
|
356 |
|
protected function defaultExpressionBuilders(): array |
|
75
|
|
|
{ |
|
76
|
356 |
|
return array_merge( |
|
77
|
356 |
|
parent::defaultExpressionBuilders(), |
|
78
|
|
|
[ |
|
79
|
356 |
|
JsonExpression::class => JsonExpressionBuilder::class, |
|
80
|
|
|
] |
|
81
|
|
|
); |
|
82
|
|
|
} |
|
83
|
|
|
} |
|
84
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths