Issue #2454733 by amateescu: Add a user-space case-insensitive collation to the SQLite driver
parent
3142e86d7c
commit
ed6b8823bb
|
@ -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.
|
||||
*
|
||||
|
|
|
@ -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']));
|
||||
|
|
|
@ -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'])) {
|
||||
|
|
Loading…
Reference in New Issue