Skip to content

Commit ed3519c

Browse files
authored
Return no results, rather than throwing an exception when ->in() is passed an empty array. (#35)
1 parent 0ab6f6f commit ed3519c

File tree

4 files changed

+11
-8
lines changed

4 files changed

+11
-8
lines changed

lib/PicoDb/Builder/BaseConditionBuilder.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -243,7 +243,7 @@ public function in($column, array $values)
243243
$this->addCondition($this->db->escapeIdentifier($column).' IN ('.implode(', ', array_fill(0, count($values), '?')).')');
244244
$this->values = array_merge($this->values, $values);
245245
} else {
246-
throw new \InvalidArgumentException('$values must not be an empty array');
246+
$this->addCondition('0 = 1');
247247
}
248248
}
249249

tests/MysqlTableTest.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,9 +137,10 @@ public function testConditionIn()
137137
$this->assertEquals('SELECT * FROM `test` WHERE `a` IN (?, ?)', $table->in('a', array('b', 'c'))->buildSelectQuery());
138138
$this->assertEquals(array('b', 'c'), $table->getConditionBuilder()->getValues());
139139

140-
$this->expectException(\InvalidArgumentException::class);
141140
$table = $this->db->table('test');
142-
$table->in('a', array());
141+
142+
$this->assertEquals('SELECT * FROM `test` WHERE 0 = 1', $table->in('a', array())->buildSelectQuery());
143+
$this->assertEquals(array(), $table->getConditionBuilder()->getValues());
143144
}
144145

145146
public function testConditionInSubquery()

tests/PostgresTableTest.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -135,9 +135,10 @@ public function testConditionIn()
135135
$this->assertEquals('SELECT * FROM "test" WHERE "a" IN (?, ?)', $table->in('a', array('b', 'c'))->buildSelectQuery());
136136
$this->assertEquals(array('b', 'c'), $table->getConditionBuilder()->getValues());
137137

138-
$this->expectException(\InvalidArgumentException::class);
139138
$table = $this->db->table('test');
140-
$table->in('a', array());
139+
140+
$this->assertEquals('SELECT * FROM "test" WHERE 0 = 1', $table->in('a', array())->buildSelectQuery());
141+
$this->assertEquals(array(), $table->getConditionBuilder()->getValues());
141142
}
142143

143144
public function testConditionInSubquery()

tests/SqliteTableTest.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -129,10 +129,11 @@ public function testConditionIn()
129129

130130
$this->assertEquals('SELECT * FROM "test" WHERE "a" IN (?, ?)', $table->in('a', array('b', 'c'))->buildSelectQuery());
131131
$this->assertEquals(array('b', 'c'), $table->getConditionBuilder()->getValues());
132-
133-
$this->expectException(\InvalidArgumentException::class);
132+
134133
$table = $this->db->table('test');
135-
$table->in('a', array());
134+
135+
$this->assertEquals('SELECT * FROM "test" WHERE 0 = 1', $table->in('a', array())->buildSelectQuery());
136+
$this->assertEquals(array(), $table->getConditionBuilder()->getValues());
136137
}
137138

138139
public function testConditionInSubquery()

0 commit comments

Comments
 (0)