From 6ba4fa002b935637dbd23980d84fe337572b11dd Mon Sep 17 00:00:00 2001 From: beberlei Date: Thu, 1 Jul 2010 21:42:38 +0200 Subject: [PATCH] DDC-660 - Fix notIn() not quoting passed literals correctly. --- lib/Doctrine/ORM/Query/Expr.php | 11 ++++++++--- tests/Doctrine/Tests/ORM/Query/ExprTest.php | 17 +++++++++++++++-- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/lib/Doctrine/ORM/Query/Expr.php b/lib/Doctrine/ORM/Query/Expr.php index e071d325e..a420b67b0 100644 --- a/lib/Doctrine/ORM/Query/Expr.php +++ b/lib/Doctrine/ORM/Query/Expr.php @@ -1,7 +1,5 @@ * @author Jonathan Wage * @author Roman Borschel + * @author Benjamin Eberlei * @todo Rename: ExpressionBuilder */ class Expr @@ -435,6 +433,13 @@ class Expr */ public function notIn($x, $y) { + if (is_array($y)) { + foreach ($y as &$literal) { + if ( ! ($literal instanceof Expr\Literal)) { + $literal = $this->_quoteLiteral($literal); + } + } + } return new Expr\Func($x . ' NOT IN', (array) $y); } diff --git a/tests/Doctrine/Tests/ORM/Query/ExprTest.php b/tests/Doctrine/Tests/ORM/Query/ExprTest.php index 032411761..fffcf8afd 100644 --- a/tests/Doctrine/Tests/ORM/Query/ExprTest.php +++ b/tests/Doctrine/Tests/ORM/Query/ExprTest.php @@ -1,7 +1,5 @@ assertEquals('u.id IN(1, 2, 3)', (string) $this->_expr->in('u.id', array(1, 2, 3))); } + public function testInLiteralExpr() + { + $this->assertEquals("u.type IN('foo', 'bar')", (string) $this->_expr->in('u.type', array('foo', 'bar'))); + } + + public function testNotInExpr() + { + $this->assertEquals('u.id NOT IN(1, 2, 3)', (string) $this->_expr->notIn('u.id', array(1, 2, 3))); + } + + public function testNotInLiteralExpr() + { + $this->assertEquals("u.type NOT IN('foo', 'bar')", (string) $this->_expr->notIn('u.type', array('foo', 'bar'))); + } + public function testAndxOrxExpr() { $andExpr = $this->_expr->andx();