Closed
Description
Bug Report
Q | A |
---|---|
BC Break | no |
Version | ~1.2 |
Summary
Having this dql code:
# UserRepository.php
public function testCoalesce()
{
return $this
->createQueryBuilder('u')
->select("GROUP_CONCAT(COALESCE(u.id), 0) SEPARATOR ', '")
->groupBy('u.id')
->getQuery()
->getArrayResult()
;
}
Current behavior
When executing the query, it throws this error:
https://imgur.com/a/Odx0HJE
Seems like writing COALESCE function inside GROUP_CONCAT function is not working, even though I have the CoalesceExpression()
method inside vendor/doctrine/orm/lib/Doctrine/ORM/Query/Parser.php
class.
/**
* CoalesceExpression ::= "COALESCE" "(" ScalarExpression {"," ScalarExpression}* ")"
*
* @return \Doctrine\ORM\Query\AST\CoalesceExpression
*/
public function CoalesceExpression()
{
$this->match(Lexer::T_COALESCE);
$this->match(Lexer::T_OPEN_PARENTHESIS);
// Process ScalarExpressions (1..N)
$scalarExpressions = array();
$scalarExpressions[] = $this->ScalarExpression();
while ($this->lexer->isNextToken(Lexer::T_COMMA)) {
$this->match(Lexer::T_COMMA);
$scalarExpressions[] = $this->ScalarExpression();
}
$this->match(Lexer::T_CLOSE_PARENTHESIS);
return new AST\CoalesceExpression($scalarExpressions);
}
How to reproduce
added DQL code above
If I write the equivalent SQL code inside the repo's method, then it works as expected.
#UserRepository.php
$db = $this->getEntityManager()->getConnection();
$sql = "SELECT GROUP_CONCAT(COALESCE(u.id, 0) SEPARATOR ', ') AS tst FROM User u GROUP BY u.id";
$stmt = $db->prepare($sql);
$stmt->execute();
return $stmt->fetchAll();
Please, help.