doctrine/doctrine2 — pull request #439 by stefanklug (2012-09-07 13:10:29+00:00)
Title: Parser returns string instead of Literal expression

Hi,
I have this patch lying here for some time now, and would like to propose it for the main development line.
The Problem is, that Parser::StringPrimary() returns a raw string instead of a Literal object of type String. This behaviour requires additional logic when adding custom DQL functions to doctrine.

The problem is, that this change can be considered a breaking change, for everyone relying on the current (inconsistent) behaviour.

One example to illustrate the Problem. Lets say we implement our custom MyToUpper function:

class MyToUpper extends FunctionNode
{
public $content = null;

public function parse(\Doctrine\ORM\Query\Parser $parser)
{
$parser->match(Lexer::T_IDENTIFIER);
$parser->match(Lexer::T_OPEN_PARENTHESIS);
$this->content = $parser->StringPrimary();
$parser->match(Lexer::T_CLOSE_PARENTHESIS);
}

public function getSql(\Doctrine\ORM\Query\SqlWalker $sqlWalker)
{
//this will break for a string constant
return 'NativeToUpper(' .$this->content->dispatch($sqlWalker) . ')';
}
}

This implementation works for MyToUpper(user.name) but crashes for MyToUpper('someConstant')