Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: QueryBuilder limit(0) bug #8280

Merged
merged 14 commits into from
Dec 16, 2023
Prev Previous commit
Next Next commit
fix: limit(0) and get($limit) behavior
  • Loading branch information
kenjis committed Dec 9, 2023
commit a05bfebe73c4881365f61745782732590cea3977
8 changes: 6 additions & 2 deletions system/Database/BaseBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -1489,6 +1489,10 @@ public function orderBy(string $orderBy, string $direction = '', ?bool $escape =
*/
public function limit(?int $value = null, ?int $offset = 0)
{
if (config(Feature::class)->limitZeroAsAll && $value === 0) {
$value = null;
}

if ($value !== null) {
$this->QBLimit = $value;
}
Expand Down Expand Up @@ -1606,8 +1610,8 @@ protected function compileFinalQuery(string $sql): string
*/
public function get(?int $limit = null, int $offset = 0, bool $reset = true)
{
if (config(Feature::class)->limitZeroAsAll) {
$limit ??= 0;
if (config(Feature::class)->limitZeroAsAll && $limit === 0) {
$limit = null;
}

if ($limit !== null) {
Expand Down
4 changes: 4 additions & 0 deletions system/Database/SQLSRV/Builder.php
Original file line number Diff line number Diff line change
Expand Up @@ -618,6 +618,10 @@ protected function compileSelect($selectOverride = false): string
*/
public function get(?int $limit = null, int $offset = 0, bool $reset = true)
{
if (config(Feature::class)->limitZeroAsAll && $limit === 0) {
$limit = null;
}

if ($limit !== null) {
$this->limit($limit, $offset);
}
Expand Down