diff --git a/lib/Doctrine/ORM/Query/Expr/Base.php b/lib/Doctrine/ORM/Query/Expr/Base.php index 93bca7507..abe7e54be 100644 --- a/lib/Doctrine/ORM/Query/Expr/Base.php +++ b/lib/Doctrine/ORM/Query/Expr/Base.php @@ -55,7 +55,7 @@ abstract class Base public function add($arg) { - if ( ! empty($arg) || ($arg instanceof self && $arg->count() > 0)) { + if ( $arg !== null || ($arg instanceof self && $arg->count() > 0)) { // If we decide to keep Expr\Base instances, we can use this check if ( ! is_string($arg)) { $class = get_class($arg); diff --git a/tests/Doctrine/Tests/ORM/QueryBuilderTest.php b/tests/Doctrine/Tests/ORM/QueryBuilderTest.php index 2cde45223..963b64ce7 100644 --- a/tests/Doctrine/Tests/ORM/QueryBuilderTest.php +++ b/tests/Doctrine/Tests/ORM/QueryBuilderTest.php @@ -681,4 +681,32 @@ class QueryBuilderTest extends \Doctrine\Tests\OrmTestCase $this->assertEquals('SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u INNER JOIN u.groups g', $qb->getDQL()); } + + /** + * @group DDC-1211 + */ + public function testEmptyStringLiteral() + { + $expr = $this->_em->getExpressionBuilder(); + $qb = $this->_em->createQueryBuilder() + ->select('u') + ->from('Doctrine\Tests\Models\CMS\CmsUser', 'u') + ->where($expr->eq('u.username', $expr->literal(""))); + + $this->assertEquals("SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.username = ''", $qb->getDQL()); + } + + /** + * @group DDC-1211 + */ + public function testEmptyNumericLiteral() + { + $expr = $this->_em->getExpressionBuilder(); + $qb = $this->_em->createQueryBuilder() + ->select('u') + ->from('Doctrine\Tests\Models\CMS\CmsUser', 'u') + ->where($expr->eq('u.username', $expr->literal(0))); + + $this->assertEquals('SELECT u FROM Doctrine\Tests\Models\CMS\CmsUser u WHERE u.username = 0', $qb->getDQL()); + } } \ No newline at end of file