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
|
.. code-block:: php
|
||||||
|
|
||||||
AggregateExpression ::= ("AVG" | "MAX" | "MIN" | "SUM") "(" ["DISTINCT"] StateFieldPathExpression ")" |
|
AggregateExpression ::= ("AVG" | "MAX" | "MIN" | "SUM" | "COUNT") "(" ["DISTINCT"] SimpleArithmeticExpression ")"
|
||||||
"COUNT" "(" ["DISTINCT"] (IdentificationVariable | SingleValuedPathExpression) ")"
|
|
||||||
|
|
||||||
Case Expressions
|
Case Expressions
|
||||||
~~~~~~~~~~~~~~~~
|
~~~~~~~~~~~~~~~~
|
||||||
|
@ -2939,8 +2939,7 @@ class Parser
|
|||||||
|
|
||||||
/**
|
/**
|
||||||
* AggregateExpression ::=
|
* AggregateExpression ::=
|
||||||
* ("AVG" | "MAX" | "MIN" | "SUM") "(" ["DISTINCT"] StateFieldPathExpression ")" |
|
* ("AVG" | "MAX" | "MIN" | "SUM" | "COUNT") "(" ["DISTINCT"] SimpleArithmeticExpression ")"
|
||||||
* "COUNT" "(" ["DISTINCT"] (IdentificationVariable | SingleValuedPathExpression) ")"
|
|
||||||
*
|
*
|
||||||
* @return \Doctrine\ORM\Query\AST\AggregateExpression
|
* @return \Doctrine\ORM\Query\AST\AggregateExpression
|
||||||
*/
|
*/
|
||||||
@ -2962,9 +2961,7 @@ class Parser
|
|||||||
$isDistinct = true;
|
$isDistinct = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
$pathExp = ($lookaheadType === Lexer::T_COUNT)
|
$pathExp = $this->SimpleArithmeticExpression();
|
||||||
? $this->SingleValuedPathExpression()
|
|
||||||
: $this->SimpleArithmeticExpression();
|
|
||||||
|
|
||||||
$this->match(Lexer::T_CLOSE_PARENTHESIS);
|
$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()
|
public function testSupportsWhereClauseWithPositionalParameter()
|
||||||
{
|
{
|
||||||
$this->assertSqlGeneration(
|
$this->assertSqlGeneration(
|
||||||
|
Loading…
x
Reference in New Issue
Block a user