Skip to content

Commit 4b8c1fb

Browse files
authored
Merge pull request #2153 from tangix/bugfix-count-result
Bug fix countAllResults with LIMIT
2 parents 7576a55 + fdf28ba commit 4b8c1fb

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
@@ -1569,6 +1569,10 @@ public function countAllResults(bool $reset = true, bool $test = false)
15691569
$this->QBOrderBy = null;
15701570
}
15711571

1572+
// We cannot use a LIMIT when getting the single row COUNT(*) result
1573+
$limit = $this->QBLimit;
1574+
$this->QBLimit = false;
1575+
15721576
$sql = ($this->QBDistinct === true)
15731577
?
15741578
$this->countString . $this->db->protectIdentifiers('numrows') . "\nFROM (\n" . $this->compileSelect() . "\n) CI_count_all_results"
@@ -1592,6 +1596,9 @@ public function countAllResults(bool $reset = true, bool $test = false)
15921596
$this->QBOrderBy = $orderBy ?? [];
15931597
}
15941598

1599+
// Restore the LIMIT setting
1600+
$this->QBLimit = $limit;
1601+
15951602
$row = (! $result instanceof ResultInterface)
15961603
? null
15971604
: $result->getRow();

0 commit comments

Comments
 (0)