Skip to content

Commit e65ff35

Browse files
committed
Use named parameters in SQL queries
1 parent 4bffd43 commit e65ff35

File tree

1 file changed

+2
-28
lines changed

1 file changed

+2
-28
lines changed

meta/QueryBuilder.php

Lines changed: 2 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ public function addValue($value)
183183
static $count = 0;
184184
$count++;
185185

186-
$placeholder = ":!!val$count!!:"; // sqlite plugin does not support named parameters, yet so we have simulate it
186+
$placeholder = ":val$count";
187187
$this->values[$placeholder] = $value;
188188
return $placeholder;
189189
}
@@ -241,33 +241,7 @@ public function getSQL()
241241
'ORDER BY ' . implode(",\n", $this->orderby) . "\n";
242242
}
243243

244-
return $this->fixPlaceholders($sql);
245-
}
246-
247-
/**
248-
* Replaces the named placeholders with ? placeholders
249-
*
250-
* Until the sqlite plugin can use named placeholder properly
251-
*
252-
* @param string $sql
253-
* @return array
254-
*/
255-
protected function fixPlaceholders($sql)
256-
{
257-
$vals = [];
258-
259-
while (preg_match('/(:!!val\d+!!:)/', $sql, $m)) {
260-
$pl = $m[1];
261-
262-
if (!array_key_exists($pl, $this->values)) {
263-
throw new StructException('Placeholder not found');
264-
}
265-
266-
$sql = preg_replace("/$pl/", '?', $sql, 1);
267-
$vals[] = $this->values[$pl];
268-
}
269-
270-
return [$sql, $vals];
244+
return [$sql, $this->values];
271245
}
272246

273247
/**

0 commit comments

Comments
 (0)