Skip to content
Permalink
Browse files

Making `IN` conditions accept an empty array

  • Loading branch information...
lorenzo committed Jul 23, 2014
1 parent 63215b0 commit d227e151b6e05d686f17595f542428761584aabb
Showing with 21 additions and 0 deletions.
  1. +5 −0 src/Database/Expression/Comparison.php
  2. +16 −0 tests/TestCase/Database/QueryTest.php
@@ -166,6 +166,11 @@ protected function _flattenValue($value, $generator, $type = null) {
foreach ($value as $k => $v) {
$parts[] = $this->_bindValue($v, $generator, $type);
}
if (empty($parts)) {
return 'SELECT NULL';
}
return implode(',', $parts);
}
@@ -591,6 +591,22 @@ public function testSelectWhereArrayType() {
$this->assertEquals(['id' => 3], $result->fetch('assoc'));
}
/**
* Tests that passing an empty array type to any where condition will not
* result in an error, but in an empty result set
*
* @return void
*/
public function testSelectWhereArrayTypeEmpty() {
$query = new Query($this->connection);
$result = $query
->select(['id'])
->from('comments')
->where(['id' => []], ['id' => 'integer[]'])
->execute();
$this->assertCount(0, $result);
}
/**
* Tests that Query::orWhere() can be used to concatenate conditions with OR
*

0 comments on commit d227e15

Please sign in to comment.
You can’t perform that action at this time.