Doctrine 1
  1. Doctrine 1
  2. DC-657

EXISTS not correctly parsed if there's no space between keyword and the open bracket

    Details

    • Type: Bug Bug
    • Status: Resolved
    • Priority: Minor Minor
    • Resolution: Fixed
    • Affects Version/s: 1.2.1
    • Fix Version/s: 1.2.3
    • Component/s: Query
    • Labels:
      None
    • Environment:
      Mac OS X 10.6.3, MySQL 5.1.34, PHP 5.2.10

      Description

      Executing a query that has an EXISTS in the WHERE clause without a space before its bracket make Doctrine ignore the EXISTS part and output it as is, this cause problems because, as an example, table aliases are not correctly resolved.

      For example this works

      SELECT * FROM TableA a WHERE EXISTS (SELECT id FROM TableB b WHERE b.a = a.id)
      

      while this doesn't

      SELECT * FROM TableA a WHERE EXISTS(SELECT id FROM TableB b WHERE b.a = a.id)
      

      I found the error could be in Doctrine/Query/Where.php line 49:

              if (count($terms) > 1) {
                  if (substr($where, 0, 6) == 'EXISTS') {
                      return $this->parseExists($where, true);
                  } elseif (substr($where, 0, 10) == 'NOT EXISTS') {
                      return $this->parseExists($where, false);
                  }
              }
      

      could be modified with:

                  if (substr($where, 0, 6) == 'EXISTS') {
                      return $this->parseExists($where, true);
                  } elseif (substr($where, 0, 10) == 'NOT EXISTS') {
                      return $this->parseExists($where, false);
                  }
      

      to solve the problem. As a plus, since one could write "NOT EXISTS" (for some reason), I think it's better to write it this way:

              if (substr($where, 0, 6) == 'EXISTS') {
                  return $this->parseExists($where, true);
              } elseif (preg_match('/^NOT\s+EXISTS\b/i', $where) !== 0) {
                  return $this->parseExists($where, false);
              }
      

      Hope this helps.

      PS. Please add php code formatter

        Activity

        There are no comments yet on this issue.

          People

          • Assignee:
            Guilherme Blanco
            Reporter:
            Andrea Baron
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved: