From 060739d72cb33ebc6a4b0fe42c40d4d7aeec01ca Mon Sep 17 00:00:00 2001 From: zYne Date: Fri, 15 Sep 2006 09:08:44 +0000 Subject: [PATCH] added Regexp operator compatibility for mysql and pgsql drivers --- Doctrine/Connection.php | 9 +++++++++ Doctrine/Connection/Mysql.php | 10 ++++++++++ Doctrine/Connection/Pgsql.php | 9 +++++++++ Doctrine/Query/Where.php | 9 +++++---- 4 files changed, 33 insertions(+), 4 deletions(-) diff --git a/Doctrine/Connection.php b/Doctrine/Connection.php index 8d12e6ec2..9aa20c628 100644 --- a/Doctrine/Connection.php +++ b/Doctrine/Connection.php @@ -126,6 +126,15 @@ abstract class Doctrine_Connection extends Doctrine_Configurable implements Coun public function getDBH() { return $this->dbh; } + /** + * returns the regular expression operator + * (implemented by the connection drivers) + * + * @return string + */ + public function getRegexpOperator() { + throw new Doctrine_Connection_Exception('Regular expression operator is not supported by this database driver.'); + } /** * query * queries the database with Doctrine Query Language diff --git a/Doctrine/Connection/Mysql.php b/Doctrine/Connection/Mysql.php index 38b41e926..478300988 100644 --- a/Doctrine/Connection/Mysql.php +++ b/Doctrine/Connection/Mysql.php @@ -14,10 +14,20 @@ class Doctrine_Connection_Mysql extends Doctrine_Connection_Common { $this->setAttribute(Doctrine::ATTR_QUERY_LIMIT, Doctrine::LIMIT_ROWS); parent::__construct($manager,$pdo); } + /** + * returns the regular expression operator + * (implemented by the connection drivers) + * + * @return string + */ + public function getRegexpOperator() { + return 'RLIKE'; + } /** * deletes all data access object from the collection * @param Doctrine_Collection $coll */ + /** public function deleteCollection(Doctrine_Collection $coll) { diff --git a/Doctrine/Connection/Pgsql.php b/Doctrine/Connection/Pgsql.php index 6bfd12afe..b76fd8c9e 100644 --- a/Doctrine/Connection/Pgsql.php +++ b/Doctrine/Connection/Pgsql.php @@ -14,5 +14,14 @@ class Doctrine_Connection_Pgsql extends Doctrine_Connection_Common { $data = $stmt->fetch(PDO::FETCH_NUM); return $data[0]; } + /** + * returns the regular expression operator + * (implemented by the connection drivers) + * + * @return string + */ + public function getRegexpOperator() { + return 'SIMILAR TO'; + } } diff --git a/Doctrine/Query/Where.php b/Doctrine/Query/Where.php index 76f69fd69..f61dd8a94 100644 --- a/Doctrine/Query/Where.php +++ b/Doctrine/Query/Where.php @@ -48,10 +48,11 @@ class Doctrine_Query_Where extends Doctrine_Query_Condition { $stack = $this->query->getTableStack(); switch($func) { - case 'contains': - - case 'similarTo': - case 'isLike': + case 'contains': + $operator = ' = '; + case 'regexp': + $operator = ' RLIKE '; + case 'like': if(empty($relation)) throw new Doctrine_Query_Exception('DQL function contains can only be used for fields of related components');