DDC-3065: Generated 'IN' clause doesn't handle 'null' values (needs to add 'IS NULL' check) #3837

doctrinebot opened this Issue Apr 3, 2014 · 5 comments

2 participants


Jira issue originally created by user samadams83:

BasicEntityPersister::getSelectSQL($criteria) first argument can take an array.
However, if that array contains an 'or' structure like so:

it is converted into:
```mycol IN (?)```
With the final query looking like:
```WHERE mycol IN ('couldbethis','orthis',null)```
The problem is, mysql will never be able to match the null.

Possible change to `getSelectConditionStatementSQL` method:

    if (is_array($value)) {
        $in = sprintf('%s IN (%s)' , $condition, $placeholder);
        $nullKey = array_search(null, $value, true);

        if ($nullKey) {
            return sprintf('(%s OR %s IS NULL)' , $in, $condition);
        } else {
            return $in;

resulting in a final query like:
WHERE (mycol IN ('couldbethis','orthis',null) OR mycol IS NULL)


Comment created by @ocramius:

Please see #998 - I applied your suggested fix and tested it carefully


Comment created by @doctrinebot:

A related Github Pull-Request [GH-998] was closed:


Comment created by @guilhermeblanco:

As of 4185a9c this issue is fixed.


Issue was closed with resolution "Fixed"

@doctrinebot doctrinebot added this to the 2.5 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