Skip to content

Commit f09ff81

Browse files
committed
Remove old logic
1 parent eb2f759 commit f09ff81

3 files changed

Lines changed: 32 additions & 14 deletions

File tree

src/Database/Adapter/Postgres.php

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1504,11 +1504,7 @@ public function find(string $collection, array $queries = [], ?int $limit = 25,
15041504
try {
15051505
$stmt = $this->getPDO()->prepare($sql);
15061506
foreach ($binds as $key => $value) {
1507-
if ($key === ":sequence") {
1508-
$stmt->bindValue($key, $value, PDO::PARAM_INT);
1509-
} else {
1510-
$stmt->bindValue($key, $value, $this->getPDOType($value));
1511-
}
1507+
$stmt->bindValue($key, $value, $this->getPDOType($value));
15121508
}
15131509

15141510
$this->execute($stmt);
@@ -1768,14 +1764,9 @@ protected function getSQLCondition(Query $query, array &$binds): string
17681764
Query::TYPE_CONTAINS => $query->onArray() ? \json_encode($value) : '%' . $this->escapeWildcards($value) . '%',
17691765
default => $value
17701766
};
1771-
if ($attribute === $this->quote("_id")) {
1772-
$binds[":sequence"] = $value;
1773-
$conditions[] = "{$alias}.{$attribute} {$operator} :sequence";
1774-
} else {
1775-
$binds[":{$placeholder}_{$key}"] = $value;
1776-
$conditions[] = "{$alias}.{$attribute} {$operator} :{$placeholder}_{$key}";
1777-
}
17781767

1768+
$binds[":{$placeholder}_{$key}"] = $value;
1769+
$conditions[] = "{$alias}.{$attribute} {$operator} :{$placeholder}_{$key}";
17791770
}
17801771

17811772
return empty($conditions) ? '' : '(' . implode(' OR ', $conditions) . ')';

src/Database/Database.php

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6673,8 +6673,22 @@ public static function convertQueries(Document $collection, array $queries): arr
66736673
}
66746674

66756675
foreach ($attributes as $attribute) {
6676-
foreach ($queries as $query) {
6676+
foreach ($queries as $index => $query) {
66776677
if ($query->getAttribute() === $attribute->getId()) {
6678+
if($query->getAttribute() === '$sequence'){
6679+
/**
6680+
* Hack for Postgres, since bindParam does not convert '' on int attribute
6681+
*/
6682+
$values = $query->getValues();
6683+
foreach ($values as $valueIndex => $value) {
6684+
if($value === ''){
6685+
$values[$valueIndex] = '0';
6686+
}
6687+
}
6688+
$query->setValues($values);
6689+
$queries[$index] = $query;
6690+
}
6691+
66786692
$query->setOnArray($attribute->getAttribute('array', false));
66796693
}
66806694
}

tests/e2e/Adapter/Scopes/DocumentTests.php

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1778,8 +1778,21 @@ public function testFindByInternalID(array $data): void
17781778
$documents = $database->find('movies', [
17791779
Query::equal('$sequence', [$data['$sequence']]),
17801780
]);
1781-
17821781
$this->assertEquals(1, count($documents));
1782+
1783+
/**
1784+
* Test getSequence returns '' Postgres bindParam issue on empty string
1785+
* Hack in convertQueries to change $sequence empty string from '' => '0'
1786+
* We should not use this fix and use structure validations, or change using not querying on empty string
1787+
*/
1788+
$empty = new Document();
1789+
1790+
/**
1791+
* Check no exceptions are thrown as a temporary fix
1792+
*/
1793+
$database->find('movies', [
1794+
Query::equal('$sequence', [$empty->getSequence()]),
1795+
]);
17831796
}
17841797

17851798
public function testFindOrderBy(): void

0 commit comments

Comments
 (0)