From ab0cdee79f08166441ee3c3d0d295bf21e507f41 Mon Sep 17 00:00:00 2001 From: Greg Anderson Date: Tue, 10 Jul 2012 22:24:43 -0700 Subject: #1575790 by greg.1.anderson: cast fields to text when using ILIKE operator on Postgres. --- includes/database/pgsql/database.inc | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/includes/database/pgsql/database.inc b/includes/database/pgsql/database.inc index 79c16b2..ab20fc4 100644 --- a/includes/database/pgsql/database.inc +++ b/includes/database/pgsql/database.inc @@ -129,6 +129,17 @@ class DatabaseConnection_pgsql extends DatabaseConnection { } } + public function prepareQuery($query) { + // In mapConditionOperator, LIKE operations are converted to ILIKE for consistency + // with mysql; however, Postgres does not support ILIKE on fields of type bytea + // (blobs). As a workaround, typecasting bytea fields to text fields allows the + // ILIKE operator to function correctly. We only need to add this typecast to + // fields that are of type bytea; however, there is no good place in the code where + // we can make this adjustment where the type of the field is known, so we settle + // on this compromise. + return parent::prepareQuery(preg_replace('/ ([^ ]*) *(I*LIKE) /i', ' ${1}::text ${2} ', $query)); + } + public function queryRange($query, $from, $count, array $args = array(), array $options = array()) { return $this->query($query . ' LIMIT ' . (int) $count . ' OFFSET ' . (int) $from, $args, $options); } -- 1.7.9.5