1
0
mirror of synced 2025-01-25 01:31:40 +03:00

Merge pull request #1122 from Ocramius/feature/support-arithmetic-expressions-in-count

Support arithmetic expressions in `COUNT()`
This commit is contained in:
Guilherme Blanco 2014-08-26 21:01:56 -04:00
commit 3d4113bd1b
3 changed files with 21 additions and 7 deletions

View File

@ -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
~~~~~~~~~~~~~~~~

View File

@ -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
*/
@ -2962,9 +2961,7 @@ class Parser
$isDistinct = true;
}
$pathExp = ($lookaheadType === Lexer::T_COUNT)
? $this->SingleValuedPathExpression()
: $this->SimpleArithmeticExpression();
$pathExp = $this->SimpleArithmeticExpression();
$this->match(Lexer::T_CLOSE_PARENTHESIS);

View File

@ -263,6 +263,24 @@ class SelectSqlGenerationTest extends \Doctrine\Tests\OrmTestCase
);
}
/**
* @group DDC-3276
*/
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(