Browse Source

Merge pull request #1153 from nojimage/db-postgres-regexp-ops

Postgres datasource support regular expression operators.

Fixes #3641
Mark Story 13 years ago
parent
commit
f8ed535e64

+ 7 - 0
lib/Cake/Model/Datasource/Database/Postgres.php

@@ -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.

+ 12 - 0
lib/Cake/Test/Case/Model/Datasource/Database/PostgresTest.php

@@ -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