DDC-2018: [GH-439] Parser returns string instead of Literal expression #2540

Closed
opened 2026-01-22 13:56:16 +01:00 by admin · 3 comments
Owner

Originally created by @doctrinebot on GitHub (Sep 7, 2012).

Originally assigned to: @beberlei on GitHub.

Jira issue originally created by user @beberlei:

This issue is created automatically through a Github pull request on behalf of stefanklug:

Url: https://github.com/doctrine/doctrine2/pull/439

Message:

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')

Originally created by @doctrinebot on GitHub (Sep 7, 2012). Originally assigned to: @beberlei on GitHub. Jira issue originally created by user @beberlei: This issue is created automatically through a Github pull request on behalf of stefanklug: Url: https://github.com/doctrine/doctrine2/pull/439 Message: 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')
admin added the Bug label 2026-01-22 13:56:16 +01:00
admin closed this issue 2026-01-22 13:56:16 +01:00
Author
Owner

@doctrinebot commented on GitHub (Sep 7, 2012):

Comment created by @beberlei:

A related Github Pull-Request [GH-439] was closed
https://github.com/doctrine/doctrine2/pull/439

@doctrinebot commented on GitHub (Sep 7, 2012): Comment created by @beberlei: A related Github Pull-Request [GH-439] was closed https://github.com/doctrine/doctrine2/pull/439
Author
Owner

@doctrinebot commented on GitHub (Sep 17, 2012):

Issue was closed with resolution "Invalid"

@doctrinebot commented on GitHub (Sep 17, 2012): Issue was closed with resolution "Invalid"
Author
Owner

@doctrinebot commented on GitHub (Dec 6, 2013):

Comment created by @doctrinebot:

A related Github Pull-Request [GH-439] was closed:
https://github.com/doctrine/dbal/pull/439

@doctrinebot commented on GitHub (Dec 6, 2013): Comment created by @doctrinebot: A related Github Pull-Request [GH-439] was closed: https://github.com/doctrine/dbal/pull/439
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#2540