Skip to content

Commit 20ea393

Browse files
committed
fix: getWhere(), update(), delete() and $limit=0
1 parent 05645ce commit 20ea393

File tree

2 files changed

+16
-4
lines changed

2 files changed

+16
-4
lines changed

phpstan-baseline.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -833,7 +833,7 @@
833833
];
834834
$ignoreErrors[] = [
835835
'message' => '#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#',
836-
'count' => 40,
836+
'count' => 37,
837837
'path' => __DIR__ . '/system/Database/BaseBuilder.php',
838838
];
839839
$ignoreErrors[] = [

system/Database/BaseBuilder.php

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1747,7 +1747,11 @@ public function getWhere($where = null, ?int $limit = null, ?int $offset = 0, bo
17471747
$this->where($where);
17481748
}
17491749

1750-
if (! empty($limit)) {
1750+
if (config(Feature::class)->limitZeroAsAll && $limit === 0) {
1751+
$limit = null;
1752+
}
1753+
1754+
if ($limit !== null) {
17511755
$this->limit($limit, $offset);
17521756
}
17531757

@@ -2463,7 +2467,11 @@ public function update($set = null, $where = null, ?int $limit = null): bool
24632467
$this->where($where);
24642468
}
24652469

2466-
if (! empty($limit)) {
2470+
if (config(Feature::class)->limitZeroAsAll && $limit === 0) {
2471+
$limit = null;
2472+
}
2473+
2474+
if ($limit !== null) {
24672475
if (! $this->canLimitWhereUpdates) {
24682476
throw new DatabaseException('This driver does not allow LIMITs on UPDATE queries using WHERE.');
24692477
}
@@ -2780,7 +2788,11 @@ public function delete($where = '', ?int $limit = null, bool $resetData = true)
27802788

27812789
$sql = $this->_delete($this->removeAlias($table));
27822790

2783-
if (! empty($limit)) {
2791+
if (config(Feature::class)->limitZeroAsAll && $limit === 0) {
2792+
$limit = null;
2793+
}
2794+
2795+
if ($limit !== null) {
27842796
$this->QBLimit = $limit;
27852797
}
27862798

0 commit comments

Comments
 (0)