Doctrine 2 - ORM
  1. Doctrine 2 - ORM
  2. DDC-42

the DQL parser does not support boolean literal values

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 2.0-ALPHA2
    • Fix Version/s: 2.0-ALPHA3
    • Component/s: None
    • Security Level: All
    • Labels:
      None
    • Environment:
      HEAD from trunk

      Description

      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 T_TRUE and T_FALSE should also be added to ArithmeticPrimary(). (line 2048)

        Activity

        Hide
        Roman S. Borschel added a comment -

        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.

        Show
        Roman S. Borschel added a comment - 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.

          People

          • Assignee:
            Roman S. Borschel
            Reporter:
            Ismo Toijala
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: