Postgres datasource support regular expression operators. Fixes #3641
@@ -95,6 +95,13 @@ class Postgres extends DboSource {
protected $_sequenceMap = array();
/**
+ * The set of valid SQL operations usable in a WHERE statement
+ *
+ * @var array
+ */
+ protected $_sqlOps = array('like', 'ilike', 'or', 'not', 'in', 'between', '~', '~*', '!~', '!~*', 'similar to');
+
+/**
* Connects to the database using options in the given configuration array.
*
* @return boolean True if successfully connected.
@@ -487,6 +487,18 @@ class PostgresTest extends CakeTestCase {
}
+ * Tests passing PostgreSQL regular expression operators when building queries
+ * @return void
+ public function testRegexpOperatorConditionsParsing() {
+ $this->assertSame(' WHERE "name" ~ \'[a-z_]+\'', $this->Dbo->conditions(array('name ~' => '[a-z_]+')));
+ $this->assertSame(' WHERE "name" ~* \'[a-z_]+\'', $this->Dbo->conditions(array('name ~*' => '[a-z_]+')));
+ $this->assertSame(' WHERE "name" !~ \'[a-z_]+\'', $this->Dbo->conditions(array('name !~' => '[a-z_]+')));
+ $this->assertSame(' WHERE "name" !~* \'[a-z_]+\'', $this->Dbo->conditions(array('name !~*' => '[a-z_]+')));
+ }
* Tests the syntax of generated schema indexes
* @return void