diff --git a/core/lib/Drupal/Core/Database/Query/Condition.php b/core/lib/Drupal/Core/Database/Query/Condition.php index 00e9015..1c91d9b 100644 --- a/core/lib/Drupal/Core/Database/Query/Condition.php +++ b/core/lib/Drupal/Core/Database/Query/Condition.php @@ -245,22 +245,21 @@ public function compile(Connection $connection, PlaceholderInterface $queryPlace // For simplicity, we first convert to an array, so that we can handle // the single and multi value cases the same. if (!is_array($condition['value'])) { - if ($operator['operator'] == 'IN' && $condition['value'] instanceof ConditionInterface) { - // Special case: IN is followed by a select query instead of a set - // of values: unset prefix and postfix to prevent double brackets. + if ($condition['value'] instanceof SelectInterface && ($operator['operator'] === 'IN' || $operator['operator'] === 'NOT IN')) { + // Special case: IN is followed by a single select query instead + // of a set of values: unset prefix and postfix to prevent double + // brackets. $operator['prefix'] = ''; $operator['postfix'] = ''; - } - $condition['value'] = array($condition['value']); } // Process all individual values. $value_fragment = array(); foreach ($condition['value'] as $value) { - if ($value instanceof ConditionInterface) { - // Right hand part is a subquery. Compile, assure that brackets - // are put around it and collect any arguments. + if ($value instanceof SelectInterface) { + // Right hand part is a subquery. Compile, put brackets around it + // and collect any arguments. $value->compile($connection, $queryPlaceholder); $value_fragment[] = '(' . (string) $value . ')'; $arguments += $value->arguments(); @@ -347,15 +346,18 @@ protected function mapConditionOperator($operator) { // $specials does not use drupal_static as its value never changes. static $specials = array( 'BETWEEN' => array('delimiter' => ' AND '), + 'NOT BETWEEN' => array('delimiter' => ' AND '), 'IN' => array('delimiter' => ', ', 'prefix' => '(', 'postfix' => ')'), 'NOT IN' => array('delimiter' => ', ', 'prefix' => '(', 'postfix' => ')'), - 'EXISTS' => array('prefix' => '(', 'postfix' => ')'), - 'NOT EXISTS' => array('prefix' => '(', 'postfix' => ')'), 'IS NULL' => array('use_value' => FALSE), 'IS NOT NULL' => array('use_value' => FALSE), // Use backslash for escaping wildcard characters. 'LIKE' => array('postfix' => " ESCAPE '\\\\'"), 'NOT LIKE' => array('postfix' => " ESCAPE '\\\\'"), + // Exists expects an already bracketed subquery as right hand part. Do + // not define additional brackets. + 'EXISTS' => array(), + 'NOT EXISTS' => array(), // These ones are here for performance reasons. '=' => array(), '<' => array(),