diff --git a/core/lib/Drupal/Component/Utility/Unicode.php b/core/lib/Drupal/Component/Utility/Unicode.php index f163a1495d4..94c4bcf5e80 100644 --- a/core/lib/Drupal/Component/Utility/Unicode.php +++ b/core/lib/Drupal/Component/Utility/Unicode.php @@ -541,6 +541,22 @@ EOD; return $string; } + /** + * Compares UTF-8-encoded strings in a binary safe case-insensitive manner. + * + * @param string $str1 + * The first string. + * @param string $str2 + * The second string. + * + * @return int + * Returns < 0 if $str1 is less than $str2; > 0 if $str1 is greater than + * $str2, and 0 if they are equal. + */ + public static function strCaseCmp($str1 , $str2) { + return strcmp(mb_strtoupper($str1, 'utf-8'), mb_strtoupper($str2, 'utf-8')); + } + /** * Encodes MIME/HTTP headers that contain incorrectly encoded characters. * diff --git a/core/lib/Drupal/Core/Database/Driver/sqlite/Connection.php b/core/lib/Drupal/Core/Database/Driver/sqlite/Connection.php index b499b5a567a..37ad89bb074 100644 --- a/core/lib/Drupal/Core/Database/Driver/sqlite/Connection.php +++ b/core/lib/Drupal/Core/Database/Driver/sqlite/Connection.php @@ -124,6 +124,9 @@ class Connection extends DatabaseConnection { $pdo->sqliteCreateFunction('rand', array(__CLASS__, 'sqlFunctionRand')); $pdo->sqliteCreateFunction('regexp', array(__CLASS__, 'sqlFunctionRegexp')); + // Create a user-space case-insensitive collation with UTF-8 support. + $pdo->sqliteCreateCollation('NOCASE_UTF8', array('Drupal\Component\Utility\Unicode', 'strCaseCmp')); + // Execute sqlite init_commands. if (isset($connection_options['init_commands'])) { $pdo->exec(implode('; ', $connection_options['init_commands'])); diff --git a/core/lib/Drupal/Core/Database/Driver/sqlite/Schema.php b/core/lib/Drupal/Core/Database/Driver/sqlite/Schema.php index 4401f65bf46..6673d1fbaed 100644 --- a/core/lib/Drupal/Core/Database/Driver/sqlite/Schema.php +++ b/core/lib/Drupal/Core/Database/Driver/sqlite/Schema.php @@ -160,8 +160,14 @@ class Schema extends DatabaseSchema { else { $sql = $name . ' ' . $spec['sqlite_type']; - if (in_array($spec['sqlite_type'], array('VARCHAR', 'TEXT')) && isset($spec['length'])) { - $sql .= '(' . $spec['length'] . ')'; + if (in_array($spec['sqlite_type'], array('VARCHAR', 'TEXT'))) { + if (isset($spec['length'])) { + $sql .= '(' . $spec['length'] . ')'; + } + + if (isset($spec['binary']) && $spec['binary'] === FALSE) { + $sql .= ' COLLATE NOCASE_UTF8'; + } } if (isset($spec['not null'])) {