Skip to content

Commit

Permalink
fix: getWhere(), update(), delete() and $limit=0
Browse files Browse the repository at this point in the history
  • Loading branch information
kenjis committed Dec 12, 2023
1 parent 05645ce commit 20ea393
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
2 changes: 1 addition & 1 deletion phpstan-baseline.php
Original file line number Diff line number Diff line change
Expand Up @@ -833,7 +833,7 @@
];
$ignoreErrors[] = [
'message' => '#^Construct empty\\(\\) is not allowed\\. Use more strict comparison\\.$#',
'count' => 40,
'count' => 37,
'path' => __DIR__ . '/system/Database/BaseBuilder.php',
];
$ignoreErrors[] = [
Expand Down
18 changes: 15 additions & 3 deletions system/Database/BaseBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -1747,7 +1747,11 @@ public function getWhere($where = null, ?int $limit = null, ?int $offset = 0, bo
$this->where($where);
}

if (! empty($limit)) {
if (config(Feature::class)->limitZeroAsAll && $limit === 0) {
$limit = null;
}

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

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

if (! empty($limit)) {
if (config(Feature::class)->limitZeroAsAll && $limit === 0) {
$limit = null;
}

if ($limit !== null) {
if (! $this->canLimitWhereUpdates) {
throw new DatabaseException('This driver does not allow LIMITs on UPDATE queries using WHERE.');
}
Expand Down Expand Up @@ -2780,7 +2788,11 @@ public function delete($where = '', ?int $limit = null, bool $resetData = true)

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

if (! empty($limit)) {
if (config(Feature::class)->limitZeroAsAll && $limit === 0) {
$limit = null;
}

if ($limit !== null) {
$this->QBLimit = $limit;
}

Expand Down

0 comments on commit 20ea393

Please sign in to comment.