Skip to content

Commit c94a5cc

Browse files
abnegateclaude
andcommitted
fix(adapter): use per-adapter quote() in fast-path SQL strings
The hot-path bypasses in find/getDocument/count/sum embedded MariaDB backtick literals (\`_uid\`, \`sum\`) directly into the SQL. Postgres uses double-quoted identifiers and rejected every fast-path query with a syntax error, breaking 595 Postgres tests. Route the column quoting through \$this->quote() so each adapter emits its own dialect. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
1 parent 01b0c6a commit c94a5cc

2 files changed

Lines changed: 5 additions & 4 deletions

File tree

phpstan-baseline.neon

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -699,7 +699,7 @@ parameters:
699699
-
700700
message: '#^Parameter \#2 \$queries of method Utopia\\Database\\Adapter\:\:find\(\) expects array\<Utopia\\Database\\Query\>, array given\.$#'
701701
identifier: argument.type
702-
count: 1
702+
count: 2
703703
path: src/Database/Database.php
704704

705705
-

src/Database/Adapter/SQL.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -604,7 +604,8 @@ public function getDocument(Document $collection, string $id, array $queries = [
604604
) {
605605
$tableExpr = $this->getSQLTable($name);
606606
$aliasQuoted = $this->quote($alias);
607-
$sql = "SELECT * FROM {$tableExpr} AS {$aliasQuoted} WHERE `_uid` = :_uid";
607+
$uidQuoted = $this->quote('_uid');
608+
$sql = "SELECT * FROM {$tableExpr} AS {$aliasQuoted} WHERE {$uidQuoted} = :_uid";
608609

609610
try {
610611
/** @var \PDOStatement|PDOStatementProxy $stmt */
@@ -1549,7 +1550,7 @@ public function count(Document $collection, array $queries = [], ?int $max = nul
15491550
&& ! $this->authorization->getStatus()
15501551
&& ! ($this->sharedTables && $this->tenant !== null)
15511552
) {
1552-
$sql = "SELECT COUNT(1) AS `sum` FROM {$this->getSQLTable($name)} AS {$this->quote($alias)}";
1553+
$sql = "SELECT COUNT(1) AS {$this->quote('sum')} FROM {$this->getSQLTable($name)} AS {$this->quote($alias)}";
15531554

15541555
try {
15551556
/** @var \PDOStatement|PDOStatementProxy $stmt */
@@ -1645,7 +1646,7 @@ public function sum(Document $collection, string $attribute, array $queries = []
16451646
&& ! $this->authorization->getStatus()
16461647
&& ! ($this->sharedTables && $this->tenant !== null)
16471648
) {
1648-
$sql = "SELECT SUM({$this->quote($attribute)}) AS `sum` FROM {$this->getSQLTable($name)} AS {$this->quote($alias)}";
1649+
$sql = "SELECT SUM({$this->quote($attribute)}) AS {$this->quote('sum')} FROM {$this->getSQLTable($name)} AS {$this->quote($alias)}";
16491650

16501651
try {
16511652
/** @var \PDOStatement|PDOStatementProxy $stmt */

0 commit comments

Comments
 (0)