From 02ba144c8dfa320e58f20cc9c8ebc5247fce29ef Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Wed, 27 Aug 2014 01:55:28 +0200 Subject: [PATCH 1/5] Adding test to verify SQL generation with an expression in `COUNT()` --- .../Tests/ORM/Query/SelectSqlGenerationTest.php | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/tests/Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php b/tests/Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php index e886307f6..0a35b3bdb 100644 --- a/tests/Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php +++ b/tests/Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php @@ -263,6 +263,21 @@ class SelectSqlGenerationTest extends \Doctrine\Tests\OrmTestCase ); } + public function testSupportsAggregateCountFunctionWithSimpleArithmetic() + { + $connMock = $this->_em->getConnection(); + $orgPlatform = $connMock->getDatabasePlatform(); + + $connMock->setDatabasePlatform(new \Doctrine\DBAL\Platforms\MySqlPlatform); + + $this->assertSqlGeneration( + 'SELECT COUNT(CONCAT(u.id, u.name)) FROM Doctrine\Tests\Models\CMS\CmsUser u GROUP BY u.id', + 'SELECT COUNT(CONCAT(c0_.id, c0_.name)) AS sclr_0 FROM cms_users c0_ GROUP BY c0_.id' + ); + + $connMock->setDatabasePlatform($orgPlatform); + } + public function testSupportsWhereClauseWithPositionalParameter() { $this->assertSqlGeneration( From 097840dc935e1cfbc93fc673be077a8fe67e8e52 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Wed, 27 Aug 2014 01:56:11 +0200 Subject: [PATCH 2/5] Allowing expression in `COUNT()` DQL aggregation functions --- lib/Doctrine/ORM/Query/Parser.php | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/lib/Doctrine/ORM/Query/Parser.php b/lib/Doctrine/ORM/Query/Parser.php index c64e731c6..ab47121ee 100644 --- a/lib/Doctrine/ORM/Query/Parser.php +++ b/lib/Doctrine/ORM/Query/Parser.php @@ -2962,9 +2962,7 @@ class Parser $isDistinct = true; } - $pathExp = ($lookaheadType === Lexer::T_COUNT) - ? $this->SingleValuedPathExpression() - : $this->SimpleArithmeticExpression(); + $pathExp = $this->SimpleArithmeticExpression(); $this->match(Lexer::T_CLOSE_PARENTHESIS); From a2e0133a94bf235498ee2e805c8ca9a147b7fa24 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Wed, 27 Aug 2014 02:01:56 +0200 Subject: [PATCH 3/5] Adding DDC-3276 test group --- tests/Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tests/Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php b/tests/Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php index 0a35b3bdb..0b5a60c96 100644 --- a/tests/Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php +++ b/tests/Doctrine/Tests/ORM/Query/SelectSqlGenerationTest.php @@ -263,6 +263,9 @@ class SelectSqlGenerationTest extends \Doctrine\Tests\OrmTestCase ); } + /** + * @group DDC-3276 + */ public function testSupportsAggregateCountFunctionWithSimpleArithmetic() { $connMock = $this->_em->getConnection(); From 45d74e72203dc47cfc889132491114351657830e Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Wed, 27 Aug 2014 02:12:08 +0200 Subject: [PATCH 4/5] DDC-3276 - #1122 - updating EBNF in docblock to reflect new syntax support --- lib/Doctrine/ORM/Query/Parser.php | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/lib/Doctrine/ORM/Query/Parser.php b/lib/Doctrine/ORM/Query/Parser.php index ab47121ee..fea4f9a12 100644 --- a/lib/Doctrine/ORM/Query/Parser.php +++ b/lib/Doctrine/ORM/Query/Parser.php @@ -2939,8 +2939,7 @@ class Parser /** * AggregateExpression ::= - * ("AVG" | "MAX" | "MIN" | "SUM") "(" ["DISTINCT"] StateFieldPathExpression ")" | - * "COUNT" "(" ["DISTINCT"] (IdentificationVariable | SingleValuedPathExpression) ")" + * ("AVG" | "MAX" | "MIN" | "SUM" | "COUNT") "(" ["DISTINCT"] SimpleArithmeticExpression ")" * * @return \Doctrine\ORM\Query\AST\AggregateExpression */ From 48a86511cb8a225c060b337ffcb6c338f7e6ed4b Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Wed, 27 Aug 2014 02:17:08 +0200 Subject: [PATCH 5/5] DDC-3276 - #1122 - updating EBNF in documentation to reflect new syntax support --- docs/en/reference/dql-doctrine-query-language.rst | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/docs/en/reference/dql-doctrine-query-language.rst b/docs/en/reference/dql-doctrine-query-language.rst index e8348350e..0161eecf9 100644 --- a/docs/en/reference/dql-doctrine-query-language.rst +++ b/docs/en/reference/dql-doctrine-query-language.rst @@ -1626,8 +1626,7 @@ Aggregate Expressions .. code-block:: php - AggregateExpression ::= ("AVG" | "MAX" | "MIN" | "SUM") "(" ["DISTINCT"] StateFieldPathExpression ")" | - "COUNT" "(" ["DISTINCT"] (IdentificationVariable | SingleValuedPathExpression) ")" + AggregateExpression ::= ("AVG" | "MAX" | "MIN" | "SUM" | "COUNT") "(" ["DISTINCT"] SimpleArithmeticExpression ")" Case Expressions ~~~~~~~~~~~~~~~~