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

Open
opened 2026-01-22 14:28:19 +01:00 by admin · 0 comments
Owner

Originally created by @doctrinebot on GitHub (Apr 3, 2014).

Originally assigned to: @guilhermeblanco on GitHub.

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:

  'mycol'=>array(
    'couldbethis','orthis',null
  )
);```
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)

Originally created by @doctrinebot on GitHub (Apr 3, 2014). Originally assigned to: @guilhermeblanco on GitHub. 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: `````` array( 'mycol'=>array( 'couldbethis','orthis',null ) );``` 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)`
admin added the Bug label 2026-01-22 14:28:19 +01:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: doctrine/archived-orm#3805