mirror of
https://github.com/silverstripe/silverstripe-sqlite3
synced 2024-10-22 17:05:37 +02:00
BUG Using GLOB for case sensitive matches in SQLite3
As opposed to LIKE, the GLOB operator is case sensitive by default in SQlite3. It uses "*" instead of "%" for wildcards, which necessitated a new SearchFilter->getWildcard() method. SQlite3 doesn't support per-term modifiers, COLLATE BINARY LIKE is case insensitive by default unless the field collation is set up accordingly. There's connection-level modifiers (PRAGMA case_sensitive_like = true), but that would affect all comparisators in the executed query.
This commit is contained in:
parent
96fdd9178a
commit
36f15a52b4
@ -1076,6 +1076,37 @@ class SQLite3Database extends SS_Database {
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
* Generate a WHERE clause for text matching.
|
||||
*
|
||||
* @param String $field Quoted field name
|
||||
* @param String $value Escaped search. Can include percentage wildcards.
|
||||
* @param boolean $exact Exact matches or wildcard support.
|
||||
* @param boolean $negate Negate the clause.
|
||||
* @param boolean $caseSensitive Enforce case sensitivity if TRUE or FALSE.
|
||||
* Stick with default collation if set to NULL.
|
||||
* @return String SQL
|
||||
*/
|
||||
public function comparisonClause($field, $value, $exact = false, $negate = false, $caseSensitive = null) {
|
||||
if($exact && !$caseSensitive) {
|
||||
$comp = ($negate) ? '!=' : '=';
|
||||
} else {
|
||||
if($caseSensitive) {
|
||||
// GLOB uses asterisks as wildcards.
|
||||
// Replace them in search string, without replacing escaped percetage signs.
|
||||
$comp = 'GLOB';
|
||||
$value = preg_replace('/^%([^\\\\])/', '*$1', $value);
|
||||
$value = preg_replace('/([^\\\\])%$/', '$1*', $value);
|
||||
$value = preg_replace('/([^\\\\])%/', '$1*', $value);
|
||||
} else {
|
||||
$comp = 'LIKE';
|
||||
}
|
||||
if($negate) $comp = 'NOT ' . $comp;
|
||||
}
|
||||
|
||||
return sprintf("%s %s '%s'", $field, $comp, $value);
|
||||
}
|
||||
|
||||
/**
|
||||
* Function to return an SQL datetime expression that can be used with SQLite3
|
||||
* used for querying a datetime in a certain format
|
||||
|
Loading…
Reference in New Issue
Block a user