Details

    • Type: Improvement Improvement
    • Status: Resolved
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 2.0.5
    • Fix Version/s: 2.2
    • Component/s: ORM
    • Security Level: All
    • Labels:
      None
    • Environment:
      MAC OSX 10.7

      Description

      When you go to compare Bit Values in MySQL Database you can do thiy by "&" or "|" If you do this with Doctrine 2 you got an exception like following:
      Message: [Syntax Error] line 0, col 161: Error: Expected =, <, <=, <>, >, >=, != got '&'

      So i fixed this problem for me:

      Doctrine\ORM\Query\Parser:
      Line 2633

          /**
           * ComparisonOperator ::= "=" | "<" | "<=" | "<>" | ">" | ">=" | "!=" | "&" | "|"
           *
           * @return string
           */
          public function ComparisonOperator()
          {
              switch ($this->_lexer->lookahead['value']) {
                  case '=':
                      $this->match(Lexer::T_EQUALS);
      
                      return '=';
      
                  case '<':
                      $this->match(Lexer::T_LOWER_THAN);
                      $operator = '<';
      
                      if ($this->_lexer->isNextToken(Lexer::T_EQUALS)) {
                          $this->match(Lexer::T_EQUALS);
                          $operator .= '=';
                      } else if ($this->_lexer->isNextToken(Lexer::T_GREATER_THAN)) {
                          $this->match(Lexer::T_GREATER_THAN);
                          $operator .= '>';
                      }
      
                      return $operator;
      
                  case '>':
                      $this->match(Lexer::T_GREATER_THAN);
                      $operator = '>';
      
                      if ($this->_lexer->isNextToken(Lexer::T_EQUALS)) {
                          $this->match(Lexer::T_EQUALS);
                          $operator .= '=';
                      }
      
                      return $operator;
      
                  case '!':
                      $this->match(Lexer::T_NEGATE);
                      $this->match(Lexer::T_EQUALS);
      
                      return '<>';
                  /* Changes by SR-RM to make Bit Oprations available */
                  case '&':
                  	$this->match(LEXER::T_BIT_AND);
                  	return '&';
                  case '|':
                  	$this->match(LEXER::T_BIT_OR);
                  	return '|';
                  /* Changes by SR-RM End */
                  default:
                      $this->syntaxError('=, <, <=, <>, >, >=, !=, &, |');
              }
          }
      

      Doctrine\ORM\Query\Lexer:
      Line 53

      /* Changes SR-RM to make Bit Oprations available */
      const T_BIT_AND             = 30;
      const T_BIT_OR               = 31;
      /* Changes by SR-RM End */
      

      Line 193

      /* Changes SR-RM to make Bit Oprations available */
      case '&': return self::T_BIT_AND;
      case '|': return self::T_BIT_OR;
      /* Changes by SR-RM End */
      

      So, maybe you gonna ad this in next Release

      Thanks or your good Job

        Activity

        Hide
        Markus Fieber added a comment -

        I do miss this patch in the recently checked out 2.2 branch. Is there any reason, it was skipped, even if the fix-version here is still 2.2?
        I really miss this feature and was unable to get it to work by applying it manually. The parser seems to have troubles applying my parameters :\

        Show
        Markus Fieber added a comment - I do miss this patch in the recently checked out 2.2 branch. Is there any reason, it was skipped, even if the fix-version here is still 2.2? I really miss this feature and was unable to get it to work by applying it manually. The parser seems to have troubles applying my parameters :\
        Hide
        Fabio B. Silva added a comment -

        Hi Markus

        The bit comparisons was been added as DQL functions,
        Can you explain your problem ?

        Show
        Fabio B. Silva added a comment - Hi Markus The bit comparisons was been added as DQL functions, Can you explain your problem ?
        Hide
        Markus Fieber added a comment - - edited

        Hi Fabio, thank you for the fast reply and the great Doctrine anyway!

        My problem is the following:
        I have an @Entity called Picture with some columns and the following

        	/** @Column(type = "integer", nullable = false)
        	 * @var int */
        	private $visibility;
        

        Now I try to fetch entities from the database that satisfy some special bit mask in this visibility attribute by doing the following:

        	/** @var $query \Doctrine\ORM\Query */
        	$query = $this->entityManager->createQuery('SELECT e FROM Classes\Models\Event e JOIN e.pictures p WHERE p.visibility & :visibility = :visibility ORDER BY p.uploadTime DESC');
        	$query->setParameter('visibility', \Classes\Session::instance()->getActualUsersRights());
        	return $query->getResult();
        

        The error reported is:

        Fatal error:  Uncaught exception 'Doctrine\ORM\Query\QueryException' with message '[Syntax Error] line 0, col 78: Error: Expected end of string, got '='' in ...\Doctrine\ORM\Query\QueryException.php:42
        Stack trace:
        #0 ...\Doctrine\ORM\Query\Parser.php(380): Doctrine\ORM\Query\QueryException::syntaxError('line 0, col 78:...')
        #1 ...\Doctrine\ORM\Query\Parser.php(745): Doctrine\ORM\Query\Parser->syntaxError('end of string')
        #2 ...\Doctrine\ORM\Query\Parser.php(213): Doctrine\ORM\Query\Parser->QueryLanguage()
        #3 ...\Doctrine\ORM\Query\Parser.php(288): Doctrine\ORM\Query\Parser->getAST()
        #4 ...\Doctrine\ORM\Query.php(231): Doctrine\ORM\Query\Parser->parse()
        #5 ...\Doctrine\ORM\Query.php(242): Doctrine\ORM\Query->_parse()
        #6 in <b>...\Doctrine\ORM\Query\QueryException.php</b> on line <b>42</b><br />
        

        Please note: I applied the above patch by hand to the Doctrine 2.2 code. Before that I got an "expected = got '&'" exception in the query.

        Am I wrong, if I look through the code and try to find the suggested lines from Ronald there? They aren't in the downloadable package and even not in the SVN, I checked out this morning from http://svn.github.com/doctrine/doctrine2.git

        Show
        Markus Fieber added a comment - - edited Hi Fabio, thank you for the fast reply and the great Doctrine anyway! My problem is the following: I have an @Entity called Picture with some columns and the following /** @Column(type = "integer", nullable = false) * @var int */ private $visibility; Now I try to fetch entities from the database that satisfy some special bit mask in this visibility attribute by doing the following: /** @var $query \Doctrine\ORM\Query */ $query = $this->entityManager->createQuery('SELECT e FROM Classes\Models\Event e JOIN e.pictures p WHERE p.visibility & :visibility = :visibility ORDER BY p.uploadTime DESC'); $query->setParameter('visibility', \Classes\Session::instance()->getActualUsersRights()); return $query->getResult(); The error reported is: Fatal error: Uncaught exception 'Doctrine\ORM\Query\QueryException' with message '[Syntax Error] line 0, col 78: Error: Expected end of string, got '='' in ...\Doctrine\ORM\Query\QueryException.php:42 Stack trace: #0 ...\Doctrine\ORM\Query\Parser.php(380): Doctrine\ORM\Query\QueryException::syntaxError('line 0, col 78:...') #1 ...\Doctrine\ORM\Query\Parser.php(745): Doctrine\ORM\Query\Parser->syntaxError('end of string') #2 ...\Doctrine\ORM\Query\Parser.php(213): Doctrine\ORM\Query\Parser->QueryLanguage() #3 ...\Doctrine\ORM\Query\Parser.php(288): Doctrine\ORM\Query\Parser->getAST() #4 ...\Doctrine\ORM\Query.php(231): Doctrine\ORM\Query\Parser->parse() #5 ...\Doctrine\ORM\Query.php(242): Doctrine\ORM\Query->_parse() #6 in <b>...\Doctrine\ORM\Query\QueryException.php</b> on line <b>42</b><br /> Please note: I applied the above patch by hand to the Doctrine 2.2 code. Before that I got an "expected = got '&'" exception in the query. Am I wrong, if I look through the code and try to find the suggested lines from Ronald there? They aren't in the downloadable package and even not in the SVN, I checked out this morning from http://svn.github.com/doctrine/doctrine2.git
        Hide
        Fabio B. Silva added a comment -

        Hi Markus

        The "&" and "|" is not available for database compatibilities
        You should use the DQL function BIT_AND or BIT_OR

        WHERE BIT_AND( p.visibility, :visibility )
        
        Show
        Fabio B. Silva added a comment - Hi Markus The "&" and "|" is not available for database compatibilities You should use the DQL function BIT_AND or BIT_OR WHERE BIT_AND( p.visibility, :visibility )
        Hide
        Markus Fieber added a comment -

        Thanks a lot Fabio,

        stupid me, sorry.

        For completeness, I now use:

        SELECT e FROM Classes\Models\Event e JOIN e.pictures p WHERE BIT_AND(p.visibility, :visibility) = :visibility ORDER BY p.uploadTime DESC
        

        and seem to get past the critical part.

        Now I can go on trying to get the project back to work with the new Doctrine 2.2
        I know its worth the work

        Show
        Markus Fieber added a comment - Thanks a lot Fabio, stupid me, sorry. For completeness, I now use: SELECT e FROM Classes\Models\Event e JOIN e.pictures p WHERE BIT_AND(p.visibility, :visibility) = :visibility ORDER BY p.uploadTime DESC and seem to get past the critical part. Now I can go on trying to get the project back to work with the new Doctrine 2.2 I know its worth the work

          People

          • Assignee:
            Fabio B. Silva
            Reporter:
            Ronald Marske
          • Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: