Skip to content

Commit 5dd4e05

Browse files
committed
SqlPreprocessor: support for IN ?
1 parent 09b4c99 commit 5dd4e05

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

src/Database/SqlPreprocessor.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ public function process(array $params, bool $useParams = false): array
103103
$this->arrayMode = null;
104104
$res[] = Nette\Utils\Strings::replace(
105105
$param,
106-
'~\'[^\']*+\'|"[^"]*+"|\?[a-z]*|^\s*+(?:\(?\s*SELECT|INSERT|UPDATE|DELETE|REPLACE|EXPLAIN)\b|\b(?:SET|WHERE|HAVING|ORDER BY|GROUP BY|KEY UPDATE)(?=\s*$|\s*\?)|\bIN\s+\(\?\)|/\*.*?\*/|--[^\n]*~Dsi',
106+
'~\'[^\']*+\'|"[^"]*+"|\?[a-z]*|^\s*+(?:\(?\s*SELECT|INSERT|UPDATE|DELETE|REPLACE|EXPLAIN)\b|\b(?:SET|WHERE|HAVING|ORDER BY|GROUP BY|KEY UPDATE)(?=\s*$|\s*\?)|\bIN\s+(?:\?|\(\?\))|/\*.*?\*/|--[^\n]*~Dsi',
107107
\Closure::fromCallable([$this, 'callback'])
108108
);
109109
} else {

tests/Database/SqlPreprocessor.phpt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,10 @@ test('IN', function () use ($preprocessor) {
8383
[$sql, $params] = $preprocessor->process(['SELECT * FROM table WHERE ? AND id IN (?) AND ?', ['a' => 111], [3, 4], ['b' => 222]]);
8484
Assert::same(reformat('SELECT * FROM table WHERE ([a] = ?) AND id IN (?, ?) AND ([b] = ?)'), $sql);
8585
Assert::same([111, 3, 4, 222], $params);
86+
87+
[$sql, $params] = $preprocessor->process(['SELECT id FROM author WHERE id IN ?', [10, 11]]); // without ()
88+
Assert::same('SELECT id FROM author WHERE id IN (?, ?)', $sql);
89+
Assert::same([10, 11], $params);
8690
});
8791

8892

0 commit comments

Comments
 (0)