Commit ed6b8823 authored by webchick's avatar webchick

Issue #2454733 by amateescu: Add a user-space case-insensitive collation to the SQLite driver

parent 3142e86d
......@@ -541,6 +541,22 @@ public static function truncate($string, $max_length, $wordsafe = FALSE, $add_el
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.
*
......
......@@ -124,6 +124,9 @@ public static function open(array &$connection_options = array()) {
$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']));
......
......@@ -160,10 +160,16 @@ protected function createFieldSql($name, $spec) {
else {
$sql = $name . ' ' . $spec['sqlite_type'];
if (in_array($spec['sqlite_type'], array('VARCHAR', 'TEXT')) && isset($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'])) {
if ($spec['not null']) {
$sql .= ' NOT NULL';
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment