From 841bdd5ca52d2849b8091c56f99e201d169e1639 Mon Sep 17 00:00:00 2001 From: Guilherme Blanco Date: Thu, 17 Apr 2014 04:39:26 +0000 Subject: [PATCH] DDC-2827 Added support for AggregateExpressions in NullComparisonExpression. --- docs/en/reference/dql-doctrine-query-language.rst | 2 +- lib/Doctrine/ORM/Query/Parser.php | 6 +++++- tests/Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php | 5 +++++ 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/docs/en/reference/dql-doctrine-query-language.rst b/docs/en/reference/dql-doctrine-query-language.rst index 0542d0191..657d5520e 100644 --- a/docs/en/reference/dql-doctrine-query-language.rst +++ b/docs/en/reference/dql-doctrine-query-language.rst @@ -1647,7 +1647,7 @@ QUANTIFIED/BETWEEN/COMPARISON/LIKE/NULL/EXISTS InstanceOfExpression ::= IdentificationVariable ["NOT"] "INSTANCE" ["OF"] (InstanceOfParameter | "(" InstanceOfParameter {"," InstanceOfParameter}* ")") InstanceOfParameter ::= AbstractSchemaName | InputParameter LikeExpression ::= StringExpression ["NOT"] "LIKE" StringPrimary ["ESCAPE" char] - NullComparisonExpression ::= (InputParameter | NullIfExpression | CoalesceExpression | SingleValuedPathExpression | ResultVariable) "IS" ["NOT"] "NULL" + NullComparisonExpression ::= (InputParameter | NullIfExpression | CoalesceExpression | AggregateExpression | FunctionDeclaration | IdentificationVariable | SingleValuedPathExpression | ResultVariable) "IS" ["NOT"] "NULL" ExistsExpression ::= ["NOT"] "EXISTS" "(" Subselect ")" ComparisonOperator ::= "=" | "<" | "<=" | "<>" | ">" | ">=" | "!=" diff --git a/lib/Doctrine/ORM/Query/Parser.php b/lib/Doctrine/ORM/Query/Parser.php index ba407034c..9b7103166 100644 --- a/lib/Doctrine/ORM/Query/Parser.php +++ b/lib/Doctrine/ORM/Query/Parser.php @@ -3131,7 +3131,7 @@ class Parser } /** - * NullComparisonExpression ::= (InputParameter | NullIfExpression | CoalesceExpression | SingleValuedPathExpression | ResultVariable) "IS" ["NOT"] "NULL" + * NullComparisonExpression ::= (InputParameter | NullIfExpression | CoalesceExpression | AggregateExpression | FunctionDeclaration | IdentificationVariable | SingleValuedPathExpression | ResultVariable) "IS" ["NOT"] "NULL" * * @return \Doctrine\ORM\Query\AST\NullComparisonExpression */ @@ -3151,6 +3151,10 @@ class Parser case $this->lexer->isNextToken(Lexer::T_COALESCE): $expr = $this->CoalesceExpression(); break; + + case $this->isAggregateFunction($this->lexer->lookahead['type']): + $expr = $this->AggregateExpression(); + break; case $this->isFunction(): $expr = $this->FunctionDeclaration(); diff --git a/tests/Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php b/tests/Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php index e26790b9b..339363191 100644 --- a/tests/Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php +++ b/tests/Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php @@ -2062,6 +2062,11 @@ class SelectSqlGenerationTest extends \Doctrine\Tests\OrmTestCase 'SELECT u.name FROM Doctrine\Tests\Models\CMS\CmsUser u HAVING u.username IS NULL', 'SELECT c0_.name AS name_0 FROM cms_users c0_ HAVING c0_.username IS NULL' ); + + $this->assertSqlGeneration( + 'SELECT u.name FROM Doctrine\Tests\Models\CMS\CmsUser u HAVING MAX(u.name) IS NULL', + 'SELECT c0_.name AS name_0 FROM cms_users c0_ HAVING MAX(c0_.name) IS NULL' + ); } /**