From d4cc87e246f4b8b5ed7cba4f25d8be3b0a1e2c0f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Vo=C5=99=C3=AD=C5=A1ek?= Date: Tue, 4 May 2021 11:35:37 +0200 Subject: [PATCH] Where does no longer accept array for OR conditions (#231) --- phpunit-mssql.xml.dist | 2 +- phpunit-mysql.xml.dist | 2 +- phpunit-oracle.xml.dist | 2 +- phpunit-pgsql.xml.dist | 2 +- phpunit.xml.dist | 2 +- src/Query.php | 37 ++++++------------------------------- tests/QueryTest.php | 25 ------------------------- 7 files changed, 11 insertions(+), 61 deletions(-) diff --git a/phpunit-mssql.xml.dist b/phpunit-mssql.xml.dist index 70f99d7a..a112c222 100644 --- a/phpunit-mssql.xml.dist +++ b/phpunit-mssql.xml.dist @@ -13,7 +13,7 @@ - + src diff --git a/phpunit-mysql.xml.dist b/phpunit-mysql.xml.dist index 5a83a908..cc92c9d8 100644 --- a/phpunit-mysql.xml.dist +++ b/phpunit-mysql.xml.dist @@ -13,7 +13,7 @@ - + src diff --git a/phpunit-oracle.xml.dist b/phpunit-oracle.xml.dist index 2457ba0e..9b235965 100644 --- a/phpunit-oracle.xml.dist +++ b/phpunit-oracle.xml.dist @@ -13,7 +13,7 @@ - + src diff --git a/phpunit-pgsql.xml.dist b/phpunit-pgsql.xml.dist index 96946343..777bbcc7 100644 --- a/phpunit-pgsql.xml.dist +++ b/phpunit-pgsql.xml.dist @@ -13,7 +13,7 @@ - + src diff --git a/phpunit.xml.dist b/phpunit.xml.dist index 219bcf44..c49c2dd5 100644 --- a/phpunit.xml.dist +++ b/phpunit.xml.dist @@ -13,7 +13,7 @@ - + src diff --git a/src/Query.php b/src/Query.php index edf5e118..bdb104da 100644 --- a/src/Query.php +++ b/src/Query.php @@ -534,27 +534,10 @@ public function _render_join() * surrounded by brackets: * $q->where('user_id',$q->dsql()->table('users')->field('id')); * - * You can specify OR conditions by passing single argument - array: - * $q->where([ - * ['a','is',null], - * ['b','is',null] - * ]); - * - * If entry of the OR condition is not an array, then it's assumed to - * be an expression; - * - * $q->where([ - * ['age',20], - * 'age is null' - * ]); - * - * The above use of OR conditions rely on orExpr() functionality. See - * that method for more information. - * - * To specify OR conditions + * To specify OR conditions: * $q->where($q->orExpr()->where('a',1)->where('b',1)); * - * @param mixed $field Field, array for OR or Expression + * @param mixed $field Field or Expression * @param mixed $cond Condition such as '=', '>' or 'is not' * @param mixed $value Value. Will be quoted unless you pass expression * @param string $kind Do not use directly. Use having() @@ -571,17 +554,9 @@ public function where($field, $cond = null, $value = null, $kind = 'where', $num } // Array as first argument means we have to replace it with orExpr() - if ($num_args === 1 && is_array($field)) { - // or conditions - $or = $this->orExpr(); - foreach ($field as $row) { - if (is_array($row)) { - $or->where(...$row); - } else { - $or->where($row); - } - } - $field = $or; + // remove in v2.5 + if (is_array($field)) { + throw new Exception('Array input / OR conditions is no longer supported'); } // first argument is string containing more than just a field name and no more than 2 @@ -654,7 +629,7 @@ public function where($field, $cond = null, $value = null, $kind = 'where', $num /** * Same syntax as where(). * - * @param mixed $field Field, array for OR or Expression + * @param mixed $field Field or Expression * @param string $cond Condition such as '=', '>' or 'is not' * @param string $value Value. Will be quoted unless you pass expression * diff --git a/tests/QueryTest.php b/tests/QueryTest.php index 3614cdd5..87697fe4 100644 --- a/tests/QueryTest.php +++ b/tests/QueryTest.php @@ -1339,31 +1339,6 @@ public function testCombinedWhere() ); } - /** - * Test where() when $field is passed as array. Should create OR conditions. - * - * @covers ::_render_orwhere - * @covers ::_render_where - * @covers ::orExpr - * @covers ::where - */ - public function testOrWhere() - { - $this->assertSame( - 'select "name" from "employee" where ("a" = :a or "b" = :b)', - $this->q() - ->field('name')->table('employee')->where([['a', 1], ['b', 1]]) - ->render() - ); - - $this->assertSame( - 'select "name" from "employee" where ("a" = :a or (a=b))', - $this->q() - ->field('name')->table('employee')->where([['a', 1], 'a=b']) - ->render() - ); - } - /** * Test OrWhere and AndWhere without where condition. Should ignore them. *