Skip to content

Commit b35f6f3

Browse files
committed
Fix min/max not bound
1 parent b6541a9 commit b35f6f3

3 files changed

Lines changed: 28 additions & 14 deletions

File tree

src/Database/Adapter/MariaDB.php

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1312,12 +1312,12 @@ public function increaseDocumentAttribute(
13121312
$name = $this->filter($collection);
13131313
$attribute = $this->filter($attribute);
13141314

1315-
$sqlMax = $max ? " AND `{$attribute}` <= {$max}" : '';
1316-
$sqlMin = $min ? " AND `{$attribute}` >= {$min}" : '';
1315+
$sqlMax = $max !== null ? " AND `{$attribute}` <= :max" : '';
1316+
$sqlMin = $min !== null ? " AND `{$attribute}` >= :min" : '';
13171317

13181318
$sql = "
1319-
UPDATE {$this->getSQLTable($name)}
1320-
SET
1319+
UPDATE {$this->getSQLTable($name)}
1320+
SET
13211321
`{$attribute}` = `{$attribute}` + :val,
13221322
`_updatedAt` = :updatedAt
13231323
WHERE _uid = :_uid
@@ -1333,6 +1333,12 @@ public function increaseDocumentAttribute(
13331333
$stmt->bindValue(':val', $value);
13341334
$stmt->bindValue(':updatedAt', $updatedAt);
13351335

1336+
if ($max !== null) {
1337+
$stmt->bindValue(':max', $max);
1338+
}
1339+
if ($min !== null) {
1340+
$stmt->bindValue(':min', $min);
1341+
}
13361342
if ($this->sharedTables) {
13371343
$stmt->bindValue(':_tenant', $this->tenant);
13381344
}

src/Database/Adapter/Mongo.php

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1706,12 +1706,14 @@ public function increaseDocumentAttribute(string $collection, string $id, string
17061706
$filters['_tenant'] = $this->getTenantFilters($collection);
17071707
}
17081708

1709-
if ($max) {
1710-
$filters[$attribute] = ['$lte' => $max];
1711-
}
1712-
1713-
if ($min) {
1714-
$filters[$attribute] = ['$gte' => $min];
1709+
if ($max !== null || $min !== null) {
1710+
$filters[$attribute] = [];
1711+
if ($max !== null) {
1712+
$filters[$attribute]['$lte'] = $max;
1713+
}
1714+
if ($min !== null) {
1715+
$filters[$attribute]['$gte'] = $min;
1716+
}
17151717
}
17161718

17171719
$options = $this->getTransactionOptions();

src/Database/Adapter/Postgres.php

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1433,12 +1433,12 @@ public function increaseDocumentAttribute(string $collection, string $id, string
14331433
$name = $this->filter($collection);
14341434
$attribute = $this->filter($attribute);
14351435

1436-
$sqlMax = $max ? " AND \"{$attribute}\" <= {$max}" : "";
1437-
$sqlMin = $min ? " AND \"{$attribute}\" >= {$min}" : "";
1436+
$sqlMax = $max !== null ? " AND \"{$attribute}\" <= :max" : "";
1437+
$sqlMin = $min !== null ? " AND \"{$attribute}\" >= :min" : "";
14381438

14391439
$sql = "
1440-
UPDATE {$this->getSQLTable($name)}
1441-
SET
1440+
UPDATE {$this->getSQLTable($name)}
1441+
SET
14421442
\"{$attribute}\" = \"{$attribute}\" + :val,
14431443
\"_updatedAt\" = :updatedAt
14441444
WHERE _uid = :_uid
@@ -1454,6 +1454,12 @@ public function increaseDocumentAttribute(string $collection, string $id, string
14541454
$stmt->bindValue(':val', $value);
14551455
$stmt->bindValue(':updatedAt', $updatedAt);
14561456

1457+
if ($max !== null) {
1458+
$stmt->bindValue(':max', $max);
1459+
}
1460+
if ($min !== null) {
1461+
$stmt->bindValue(':min', $min);
1462+
}
14571463
if ($this->sharedTables) {
14581464
$stmt->bindValue(':_tenant', $this->tenant);
14591465
}

0 commit comments

Comments
 (0)