diff --git a/core/lib/Drupal/Core/Database/Driver/mysql/EntityQuery/Condition.php b/core/lib/Drupal/Core/Database/Driver/mysql/EntityQuery/Condition.php new file mode 100644 index 0000000..05d82fe --- /dev/null +++ b/core/lib/Drupal/Core/Database/Driver/mysql/EntityQuery/Condition.php @@ -0,0 +1,12 @@ +where($condition['where'], $condition['where_args']); + } + else { + $conditionContainer->condition($field, $condition['value'], $condition['operator']); + } + } + + /** + * {@inheritdoc} + */ + public static function translateCondition(&$condition, $case_sensitive) { + // For PostgreSQL for which the condition arguments need to have case + // lowered to support not case sensitive fields. + if (is_array($condition['value']) && $case_sensitive === FALSE) { + $condition['where'] = 'LOWER(' . $condition['real_field'] . ') ' . $condition['operator'] . ' ('; + $condition['where_args'] = []; + + $n = 1; + foreach ($condition['value'] as $key => $value) { + $condition['where'] .= 'LOWER(:value' . $n . '),'; + $condition['where_args'][':value' . $n] = $value; + $n++; + } + $condition['where'] = trim($condition['where'], ','); + $condition['where'] .= ')'; + } + } + +} diff --git a/core/lib/Drupal/Core/Database/Driver/sqlite/EntityQuery/Condition.php b/core/lib/Drupal/Core/Database/Driver/sqlite/EntityQuery/Condition.php new file mode 100644 index 0000000..eb79804 --- /dev/null +++ b/core/lib/Drupal/Core/Database/Driver/sqlite/EntityQuery/Condition.php @@ -0,0 +1,12 @@ +condition($field, $condition['value'], $condition['operator']); + } + + /** + * Translates the string operators to SQL equivalents. + * + * @param array $condition + * The condition array. + * @param bool|null $case_sensitive + * If the condition should be case sensitive or not, NULL if the field does + * not define it. + */ + public static function translateCondition(&$condition, $case_sensitive) { } + +} diff --git a/core/lib/Drupal/Core/Entity/Query/Sql/Condition.php b/core/lib/Drupal/Core/Entity/Query/Sql/Condition.php index f34df0e..9aea72d --- a/core/lib/Drupal/Core/Entity/Query/Sql/Condition.php +++ b/core/lib/Drupal/Core/Entity/Query/Sql/Condition.php @@ -7,10 +7,11 @@ namespace Drupal\Core\Entity\Query\Sql; -use Drupal\Core\Entity\Query\ConditionBase; -use Drupal\Core\Entity\Query\ConditionInterface; +use Drupal\Core\Database\Database; use Drupal\Core\Database\Query\SelectInterface; use Drupal\Core\Database\Query\Condition as SqlCondition; +use Drupal\Core\Entity\Query\ConditionBase; +use Drupal\Core\Entity\Query\ConditionInterface; /** * Implements entity query conditions for SQL databases. @@ -28,6 +29,8 @@ class Condition extends ConditionBase { * {@inheritdoc} */ public function compile($conditionContainer) { + $entityQueryCondition = Database::getConnection()->getDriverClass('EntityQuery\\Condition'); + // If this is not the top level condition group then the sql query is // added to the $conditionContainer object by this function itself. The // SQL query object is only necessary to pass to Query::addField() so it @@ -46,8 +49,9 @@ public function compile($conditionContainer) { else { $type = strtoupper($this->conjunction) == 'OR' || $condition['operator'] == 'IS NULL' ? 'LEFT' : 'INNER'; $field = $tables->addField($condition['field'], $type, $condition['langcode']); + $condition['real_field'] = $field; static::translateCondition($condition, $sql_query, $tables->isFieldCaseSensitive($condition['field'])); - $conditionContainer->condition($field, $condition['value'], $condition['operator']); + $entityQueryCondition::addConditionToContainer($conditionContainer, $field, $condition); } } } @@ -80,10 +84,16 @@ public function notExists($field, $langcode = NULL) { * @see \Drupal\Core\Database\Query\ConditionInterface::condition() */ public static function translateCondition(&$condition, SelectInterface $sql_query, $case_sensitive) { - // There is nothing we can do for IN (). + // There is nothing to do for IN () queries except for PostgreSQL for which + // the condition arguments need to have case lowered to support not case + // sensitive fields. if (is_array($condition['value'])) { + $entityQueryCondition = Database::getConnection()->getDriverClass('EntityQuery\\Condition'); + $entityQueryCondition::translateCondition($condition, $case_sensitive); + return; } + // Ensure that the default operator is set to simplify the cases below. if (empty($condition['operator'])) { $condition['operator'] = '=';