Merge pull request #1122 from Ocramius/feature/support-arithmetic-expressions-in-count
Support arithmetic expressions in `COUNT()`
This commit is contained in:
commit
3d4113bd1b
@ -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
|
||||
~~~~~~~~~~~~~~~~
|
||||
|
@ -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);
|
||||
|
||||
|
@ -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(
|
||||
|
Loading…
x
Reference in New Issue
Block a user