From fc7a21b567d3051544ccc1f3a69d9b9dfbffb966 Mon Sep 17 00:00:00 2001 From: Ingo Schommer Date: Tue, 11 Dec 2012 01:47:47 +0100 Subject: [PATCH] BUG Support for case sensitive searches Through newly added Database->comparisonClause() API --- code/PostgreSQLDatabase.php | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/code/PostgreSQLDatabase.php b/code/PostgreSQLDatabase.php index fa0b087..93e2941 100644 --- a/code/PostgreSQLDatabase.php +++ b/code/PostgreSQLDatabase.php @@ -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