From b35f6f399279ee2a391b02cf67fdd71a04de8556 Mon Sep 17 00:00:00 2001 From: Jake Barnby Date: Wed, 5 Nov 2025 15:52:27 +1300 Subject: [PATCH] Fix min/max not bound --- src/Database/Adapter/MariaDB.php | 14 ++++++++++---- src/Database/Adapter/Mongo.php | 14 ++++++++------ src/Database/Adapter/Postgres.php | 14 ++++++++++---- 3 files changed, 28 insertions(+), 14 deletions(-) diff --git a/src/Database/Adapter/MariaDB.php b/src/Database/Adapter/MariaDB.php index 533673edb..a6233d189 100644 --- a/src/Database/Adapter/MariaDB.php +++ b/src/Database/Adapter/MariaDB.php @@ -1312,12 +1312,12 @@ public function increaseDocumentAttribute( $name = $this->filter($collection); $attribute = $this->filter($attribute); - $sqlMax = $max ? " AND `{$attribute}` <= {$max}" : ''; - $sqlMin = $min ? " AND `{$attribute}` >= {$min}" : ''; + $sqlMax = $max !== null ? " AND `{$attribute}` <= :max" : ''; + $sqlMin = $min !== null ? " AND `{$attribute}` >= :min" : ''; $sql = " - UPDATE {$this->getSQLTable($name)} - SET + UPDATE {$this->getSQLTable($name)} + SET `{$attribute}` = `{$attribute}` + :val, `_updatedAt` = :updatedAt WHERE _uid = :_uid @@ -1333,6 +1333,12 @@ public function increaseDocumentAttribute( $stmt->bindValue(':val', $value); $stmt->bindValue(':updatedAt', $updatedAt); + if ($max !== null) { + $stmt->bindValue(':max', $max); + } + if ($min !== null) { + $stmt->bindValue(':min', $min); + } if ($this->sharedTables) { $stmt->bindValue(':_tenant', $this->tenant); } diff --git a/src/Database/Adapter/Mongo.php b/src/Database/Adapter/Mongo.php index 1eaf59138..9fd57557f 100644 --- a/src/Database/Adapter/Mongo.php +++ b/src/Database/Adapter/Mongo.php @@ -1706,12 +1706,14 @@ public function increaseDocumentAttribute(string $collection, string $id, string $filters['_tenant'] = $this->getTenantFilters($collection); } - if ($max) { - $filters[$attribute] = ['$lte' => $max]; - } - - if ($min) { - $filters[$attribute] = ['$gte' => $min]; + if ($max !== null || $min !== null) { + $filters[$attribute] = []; + if ($max !== null) { + $filters[$attribute]['$lte'] = $max; + } + if ($min !== null) { + $filters[$attribute]['$gte'] = $min; + } } $options = $this->getTransactionOptions(); diff --git a/src/Database/Adapter/Postgres.php b/src/Database/Adapter/Postgres.php index bcc12c90b..6828f6324 100644 --- a/src/Database/Adapter/Postgres.php +++ b/src/Database/Adapter/Postgres.php @@ -1433,12 +1433,12 @@ public function increaseDocumentAttribute(string $collection, string $id, string $name = $this->filter($collection); $attribute = $this->filter($attribute); - $sqlMax = $max ? " AND \"{$attribute}\" <= {$max}" : ""; - $sqlMin = $min ? " AND \"{$attribute}\" >= {$min}" : ""; + $sqlMax = $max !== null ? " AND \"{$attribute}\" <= :max" : ""; + $sqlMin = $min !== null ? " AND \"{$attribute}\" >= :min" : ""; $sql = " - UPDATE {$this->getSQLTable($name)} - SET + UPDATE {$this->getSQLTable($name)} + SET \"{$attribute}\" = \"{$attribute}\" + :val, \"_updatedAt\" = :updatedAt WHERE _uid = :_uid @@ -1454,6 +1454,12 @@ public function increaseDocumentAttribute(string $collection, string $id, string $stmt->bindValue(':val', $value); $stmt->bindValue(':updatedAt', $updatedAt); + if ($max !== null) { + $stmt->bindValue(':max', $max); + } + if ($min !== null) { + $stmt->bindValue(':min', $min); + } if ($this->sharedTables) { $stmt->bindValue(':_tenant', $this->tenant); }