[DDC-1523] Coalesce() does not work with functions Created: 09/Dec/11 Updated: 10/Dec/11 Resolved: 10/Dec/11
|Project:||Doctrine 2 - ORM|
|Reporter:||Martin Prebio||Assignee:||Guilherme Blanco|
I wanted to use COALESCE in DQL with a function (e.g. CURRENT_TIMESTAMP()). If I run this DQL, I receive a syntax error exception like this one:
montbook:marlow mprebio$ php scripts/doctrine.php orm:run-dql "select COALESCE(CURRENT_TIMESTAMP()) from Project\Entity\User user"
I've traced this error to Doctrine\ORM\Parser::ScalarExpression() which tries to interpret the current_timestamp function as a SimpleArithmeticExpression or as a StateFieldPathExpression (first if). As far as I understand this part of the parser, the function call should lead to the if part with $this->_isFunction(). Therefore I added a "and !$this->_isFunction()" to the first if clause. After this change everything works as expected: The above query returns the current timestamp (many times because of the from since DQL needs a from part).
Reordering the ifs should work too.
|Comment by Martin Prebio [ 09/Dec/11 ]|
Also the documentation at http://www.doctrine-project.org/docs/orm/2.1/en/ only mentions COALESCE in the EBNF but not in the real documentation part. At first I thought that Doctrine doesn't support coalesce at all.
|Comment by Guilherme Blanco [ 10/Dec/11 ]|
COALESCE does not exist on 2.1.
Marking as invalid, since we won't change 2.1 to support this.