Issue #2845543 by vaplas, gambry, alexpott: PostgreSQL regular expression match operators works only for text
parent
3404c72982
commit
3901464895
|
@ -204,14 +204,11 @@ class Connection extends DatabaseConnection {
|
|||
}
|
||||
|
||||
public function prepareQuery($query) {
|
||||
// mapConditionOperator converts LIKE operations to ILIKE for consistency
|
||||
// with MySQL. However, Postgres does not support ILIKE on bytea (blobs)
|
||||
// fields.
|
||||
// To make the ILIKE operator work, we type-cast bytea fields into text.
|
||||
// @todo This workaround only affects bytea fields, but the involved field
|
||||
// types involved in the query are unknown, so there is no way to
|
||||
// conditionally execute this for affected queries only.
|
||||
return parent::prepareQuery(preg_replace('/ ([^ ]+) +(I*LIKE|NOT +I*LIKE) /i', ' ${1}::text ${2} ', $query));
|
||||
// mapConditionOperator converts some operations (LIKE, REGEXP, etc.) to
|
||||
// PostgreSQL equivalents (ILIKE, ~*, etc.). However PostgreSQL doesn't
|
||||
// automatically cast the fields to the right type for these operators,
|
||||
// so we need to alter the query and add the type-cast.
|
||||
return parent::prepareQuery(preg_replace('/ ([^ ]+) +(I*LIKE|NOT +I*LIKE|~\*) /i', ' ${1}::text ${2} ', $query));
|
||||
}
|
||||
|
||||
public function queryRange($query, $from, $count, array $args = array(), array $options = array()) {
|
||||
|
|
|
@ -509,6 +509,13 @@ class SelectTest extends DatabaseTestBase {
|
|||
$this->assertEqual(count($result), count($test_group['expected']), 'Returns the expected number of rows.');
|
||||
$this->assertEqual(sort($result), sort($test_group['expected']), 'Returns the expected rows.');
|
||||
}
|
||||
|
||||
// Ensure that REGEXP filter still works with no-string type field.
|
||||
$query = $database->select('test', 't');
|
||||
$query->addField('t', 'age');
|
||||
$query->condition('t.age', '2[6]', 'REGEXP');
|
||||
$result = $query->execute()->fetchField();
|
||||
$this->assertEquals($result, '26', 'Regexp with number type.');
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
Loading…
Reference in New Issue