mirror of
https://github.com/silverstripe/silverstripe-postgresql
synced 2024-10-22 17:05:45 +02:00
BUG Support for case sensitive searches
Through newly added Database->comparisonClause() API
This commit is contained in:
parent
12e2d69c09
commit
fc7a21b567
@ -2030,6 +2030,28 @@ class PostgreSQLDatabase extends SS_Database {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 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 === null) {
|
||||
$comp = ($negate) ? '!=' : '=';
|
||||
} else {
|
||||
$comp = ($caseSensitive === true) ? 'LIKE' : 'ILIKE';
|
||||
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 Postgres
|
||||
* used for querying a datetime in a certain format
|
||||
|
Loading…
Reference in New Issue
Block a user