Skip to content

Commit fdf28ba

Browse files
committed
Bug fix countAllResults with LIMIT
1 parent 868e0d0 commit fdf28ba

1 file changed

Lines changed: 7 additions & 0 deletions

File tree

system/Database/BaseBuilder.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1552,6 +1552,10 @@ public function countAllResults(bool $reset = true, bool $test = false)
15521552
$this->QBOrderBy = null;
15531553
}
15541554

1555+
// We cannot use a LIMIT when getting the single row COUNT(*) result
1556+
$limit = $this->QBLimit;
1557+
$this->QBLimit = false;
1558+
15551559
$sql = ($this->QBDistinct === true)
15561560
?
15571561
$this->countString . $this->db->protectIdentifiers('numrows') . "\nFROM (\n" . $this->compileSelect() . "\n) CI_count_all_results"
@@ -1575,6 +1579,9 @@ public function countAllResults(bool $reset = true, bool $test = false)
15751579
$this->QBOrderBy = $orderBy ?? [];
15761580
}
15771581

1582+
// Restore the LIMIT setting
1583+
$this->QBLimit = $limit;
1584+
15781585
$row = (! $result instanceof ResultInterface)
15791586
? null
15801587
: $result->getRow();

0 commit comments

Comments
 (0)