Skip to content

Commit cd961f1

Browse files
authored
Merge pull request #617 from utopia-php/cast-sequence
$sequence cast empty string issue
2 parents 45cf27f + 0dc4b12 commit cd961f1

File tree

2 files changed

+7
-12
lines changed

2 files changed

+7
-12
lines changed

src/Database/Adapter/Postgres.php

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1558,11 +1558,7 @@ public function find(string $collection, array $queries = [], ?int $limit = 25,
15581558
try {
15591559
$stmt = $this->getPDO()->prepare($sql);
15601560
foreach ($binds as $key => $value) {
1561-
if ($key === ":sequence") {
1562-
$stmt->bindValue($key, $value, PDO::PARAM_INT);
1563-
} else {
1564-
$stmt->bindValue($key, $value, $this->getPDOType($value));
1565-
}
1561+
$stmt->bindValue($key, $value, $this->getPDOType($value));
15661562
}
15671563

15681564
$this->execute($stmt);
@@ -1822,13 +1818,9 @@ protected function getSQLCondition(Query $query, array &$binds): string
18221818
Query::TYPE_CONTAINS => $query->onArray() ? \json_encode($value) : '%' . $this->escapeWildcards($value) . '%',
18231819
default => $value
18241820
};
1825-
if ($attribute === $this->quote("_id")) {
1826-
$binds[":sequence"] = $value;
1827-
$conditions[] = "{$alias}.{$attribute} {$operator} :sequence";
1828-
} else {
1829-
$binds[":{$placeholder}_{$key}"] = $value;
1830-
$conditions[] = "{$alias}.{$attribute} {$operator} :{$placeholder}_{$key}";
1831-
}
1821+
1822+
$binds[":{$placeholder}_{$key}"] = $value;
1823+
$conditions[] = "{$alias}.{$attribute} {$operator} :{$placeholder}_{$key}";
18321824
}
18331825

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

tests/e2e/Adapter/Scopes/DocumentTests.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1845,6 +1845,9 @@ public function testFindByInternalID(array $data): void
18451845
]);
18461846

18471847
$this->assertEquals(1, count($documents));
1848+
1849+
$empty = new Document();
1850+
$this->assertEquals('', $empty->getSequence());
18481851
}
18491852

18501853
public function testFindOrderBy(): void

0 commit comments

Comments
 (0)