Skip to content
Permalink
Browse files

Use safer defaults and make it a more deliberate choice to use intuit…

…ive behavior.
  • Loading branch information...
dereuromark committed Mar 3, 2018
1 parent 6075bc4 commit 9c36a4818f360144161db261420b9e5448fef192
Showing with 12 additions and 8 deletions.
  1. +10 −6 src/Database/Query.php
  2. +2 −2 tests/TestCase/Database/QueryTest.php
@@ -893,16 +893,18 @@ public function where($conditions = null, $types = [], $overwrite = false)
* Adds an IN condition or set of conditions to be used in the WHERE clause for this
* query.
*
* This method does allow empty inputs in contrast to where().
* This method does allow empty inputs in contrast to where() if you set
* $allowEmpty to true.
* Be careful about using it without proper sanity checks.
*
* @param string $field Field
* @param array $values Array of values
* @param bool $allowEmpty Allow empty array
* @return $this
*/
public function whereIn($field, array $values)
public function whereIn($field, array $values, $allowEmpty = false)
{
if (!$values) {
if ($allowEmpty && !$values) {
return $this->where('1=0');
}
@@ -913,16 +915,18 @@ public function whereIn($field, array $values)
* Adds a NOT IN condition or set of conditions to be used in the WHERE clause for this
* query.
*
* This method does allow empty inputs in contrast to where().
* This method does allow empty inputs in contrast to where() if you set
* $allowEmpty to true.
* Be careful about using it without proper sanity checks.
*
* @param string $field Field
* @param array $values Array of values
* @param bool $allowEmpty Allow empty array
* @return $this
*/
public function whereNotIn($field, array $values)
public function whereNotIn($field, array $values, $allowEmpty = false)
{
if (!$values) {
if ($allowEmpty && !$values) {
return $this->where('1=1');
}
@@ -1749,7 +1749,7 @@ public function testWhereInEmpty()
$query = new Query($this->connection);
$query->select(['id'])
->from('articles')
->whereIn('id', [])
->whereIn('id', [], true)
->execute();
$sql = $query->sql();
@@ -1799,7 +1799,7 @@ public function testWhereNotInEmpty()
$query = new Query($this->connection);
$query->select(['id'])
->from('articles')
->whereNotIn('id', [])
->whereNotIn('id', [], true)
->execute();
$sql = $query->sql();

0 comments on commit 9c36a48

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