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) {
|
public function prepareQuery($query) {
|
||||||
// mapConditionOperator converts LIKE operations to ILIKE for consistency
|
// mapConditionOperator converts some operations (LIKE, REGEXP, etc.) to
|
||||||
// with MySQL. However, Postgres does not support ILIKE on bytea (blobs)
|
// PostgreSQL equivalents (ILIKE, ~*, etc.). However PostgreSQL doesn't
|
||||||
// fields.
|
// automatically cast the fields to the right type for these operators,
|
||||||
// To make the ILIKE operator work, we type-cast bytea fields into text.
|
// so we need to alter the query and add the type-cast.
|
||||||
// @todo This workaround only affects bytea fields, but the involved field
|
return parent::prepareQuery(preg_replace('/ ([^ ]+) +(I*LIKE|NOT +I*LIKE|~\*) /i', ' ${1}::text ${2} ', $query));
|
||||||
// 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));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public function queryRange($query, $from, $count, array $args = array(), array $options = array()) {
|
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(count($result), count($test_group['expected']), 'Returns the expected number of rows.');
|
||||||
$this->assertEqual(sort($result), sort($test_group['expected']), 'Returns the expected 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