Skip to content

Commit d5aa567

Browse files
committed
SqlPreprocessor: fixed IN (?) with empty array
1 parent 0735e7f commit d5aa567

2 files changed

Lines changed: 5 additions & 1 deletion

File tree

src/Database/SqlPreprocessor.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -205,7 +205,7 @@ private function formatValue($value, $mode = NULL)
205205
$vx[] = $this->delimite($k) . '=' . $this->formatValue($v);
206206
}
207207
}
208-
return implode(', ', $vx);
208+
return $vx ? implode(', ', $vx) : '1=1';
209209

210210
} elseif ($mode === 'and' || $mode === 'or') { // (key [operator] value) AND ...
211211
foreach ($value as $k => $v) {

tests/Database/SqlPreprocessor.phpt

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ test(function() use ($preprocessor) {
4646

4747

4848
test(function() use ($preprocessor) { // IN
49+
list($sql, $params) = $preprocessor->process(array('SELECT id FROM author WHERE id IN (?)', array()));
50+
Assert::same( 'SELECT id FROM author WHERE id IN (1=1)', $sql );
51+
Assert::same( array(), $params );
52+
4953
list($sql, $params) = $preprocessor->process(array('SELECT id FROM author WHERE id IN (?)', array(10, 11)));
5054
Assert::same( 'SELECT id FROM author WHERE id IN (10, 11)', $sql );
5155
Assert::same( array(), $params );

0 commit comments

Comments
 (0)