DDC-42: the DQL parser does not support boolean literal values #4918

Closed
doctrinebot opened this Issue Oct 12, 2009 · 2 comments

1 participant

@doctrinebot

Jira issue originally created by user itoijala:

The parser does not support boolean literal values. This means that comparisons like e.unlocked = true result in a syntax error. This is not what is intended, since both documentation and comments in the code Doctrine\ORM\Query\Parser.php line 1870 say that boolean literals are supported.

I have a possible fix. I don't know if it is the best way to fix this.

OLD:

/****
     * Literal ::= string | char | integer | float | boolean
     *
     * @return string
     */
    public function Literal()
    {
        switch ($this->_lexer->lookahead['type']) {
            case Lexer::T_STRING:
            case Lexer::T_INTEGER:
            case Lexer::T_FLOAT:
                $this->match($this->_lexer->lookahead['value']);
                return $this->_lexer->token['value'];
            default:
                $this->syntaxError('Literal');
        }
    }

NEW:

/****
     * Literal ::= string | char | integer | float | boolean
     *
     * @return string
     */
    public function Literal()
    {
        switch ($this->_lexer->lookahead['type']) {
            case Lexer::T_STRING:
            case Lexer::T_INTEGER:
            case Lexer::T_FLOAT:
                $this->match($this->_lexer->lookahead['value']);
                return $this->_lexer->token['value'];
            case Lexer::T_TRUE:
            case Lexer::T_FALSE:
                $this->match($this->_lexer->lookahead['value']);
                return $this->*em->getConnection()->getDatabasePlatform()->convertBooleans(strtolower($this->*lexer->token['value']) == 'true' ? true : false);
            default:
                $this->syntaxError('Literal');
        }
    }

Using convertBooleans is important. Otherwise the sql will have 'true' or 'false'.

Cases TTRUE and TFALSE should also be added to ArithmeticPrimary(). (line 2048)

@doctrinebot

Comment created by romanb:

Thanks, I will work on this.

One thing for your understanding though: The task of the parser is only to accept or deny input, thereby building up a syntax tree. Afterwards, one or more tree walkers can walk down this tree to do something with it. Normally this is just the SqlWalker that produces SQL. So it is the task of this SqlWalker to properly quote the literals. The Parser does not even care what the output will be.

@doctrinebot

Issue was closed with resolution "Fixed"

@doctrinebot doctrinebot added this to the 2.0-ALPHA3 milestone Dec 6, 2015
@doctrinebot doctrinebot closed this Dec 6, 2015
@doctrinebot doctrinebot added the Bug label Dec 7, 2015
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment