From d8d41658d3fb87c71c3e30825003f827f4ffbdae Mon Sep 17 00:00:00 2001 From: alecpl Date: Sat, 9 Aug 2008 20:20:59 +0000 Subject: [PATCH] - Case insensitive contacts searching using PostgreSQL (#1485259) --- CHANGELOG | 4 ++++ program/include/rcube_contacts.php | 6 +++--- program/include/rcube_db.php | 20 ++++++++++++++++++++ program/include/rcube_mdb2.php | 21 +++++++++++++++++++++ 4 files changed, 48 insertions(+), 3 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 042e38f0b..fad40f2f1 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,6 +1,10 @@ CHANGELOG RoundCube Webmail --------------------------- +2008/08/09 (alec) +---------- +- Case insensitive contacts searching using PostgreSQL (#1485259) + 2008/07/31 (thomasb) ---------- - Make default imap folders configurable for each user (#1485075) diff --git a/program/include/rcube_contacts.php b/program/include/rcube_contacts.php index 913f04fd3..0c0f932fc 100644 --- a/program/include/rcube_contacts.php +++ b/program/include/rcube_contacts.php @@ -196,12 +196,12 @@ class rcube_contacts if ($col == 'ID' || $col == $this->primary_key) { $ids = !is_array($value) ? split(',', $value) : $value; - $add_where[] = $this->primary_key." IN (".join(',', $ids).")"; + $add_where[] = $this->primary_key.' IN ('.join(',', $ids).')'; } else if ($strict) - $add_where[] = $this->db->quoteIdentifier($col)."=".$this->db->quote($value); + $add_where[] = $this->db->quoteIdentifier($col).'='.$this->db->quote($value); else - $add_where[] = $this->db->quoteIdentifier($col)." LIKE ".$this->db->quote(strlen($value)>2 ? "%$value%" : "$value%"); + $add_where[] = $this->db->ilike($col, '%'.$value.'%'); } if (!empty($add_where)) diff --git a/program/include/rcube_db.php b/program/include/rcube_db.php index 8fa34e6a5..716e0d9bf 100644 --- a/program/include/rcube_db.php +++ b/program/include/rcube_db.php @@ -510,6 +510,26 @@ class rcube_db } + /** + * Return SQL statement for case insensitive LIKE + * + * @param string Field name + * @param string Search value + * @return string SQL statement to use in query + * @access public + */ + function ilike($column, $value) + { + switch($this->db_provider) + { + case 'pgsql': + return $this->quote_identifier($column).' ILIKE '.$this->quote($value); + default: + return $this->quote_identifier($column).' LIKE '.$this->quote($value); + } + } + + /** * Adds a query result and returns a handle ID * diff --git a/program/include/rcube_mdb2.php b/program/include/rcube_mdb2.php index 9f2f30c10..0adb6e293 100644 --- a/program/include/rcube_mdb2.php +++ b/program/include/rcube_mdb2.php @@ -508,6 +508,27 @@ class rcube_mdb2 } + /** + * Return SQL statement for case insensitive LIKE + * + * @param string Field name + * @param string Search value + * @return string SQL statement to use in query + * @access public + */ + function ilike($column, $value) + { + // TODO: use MDB2's matchPattern() function + switch($this->db_provider) + { + case 'pgsql': + return $this->quote_identifier($column).' ILIKE '.$this->quote($value); + default: + return $this->quote_identifier($column).' LIKE '.$this->quote($value); + } + } + + /** * Adds a query result and returns a handle ID *