Details
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 ![]()