From dd73f6de4a316c58c5b1ed36f496b1e3ba25ebb6 Mon Sep 17 00:00:00 2001 From: zYne Date: Thu, 26 Oct 2006 23:05:55 +0000 Subject: [PATCH] Fixes #205 --- lib/Doctrine/Query.php | 14 ++++++++++---- tests/run.php | 4 ++-- 2 files changed, 12 insertions(+), 6 deletions(-) diff --git a/lib/Doctrine/Query.php b/lib/Doctrine/Query.php index c1505ad3c..cd00c1ea9 100644 --- a/lib/Doctrine/Query.php +++ b/lib/Doctrine/Query.php @@ -488,12 +488,18 @@ class Doctrine_Query extends Doctrine_Hydrate implements Countable { $dbh = $this->connection->getDBH(); // mysql doesn't support LIMIT in subqueries - if($dbh->getAttribute(PDO::ATTR_DRIVER_NAME) == 'mysql') { - $list = $dbh->query($subquery)->fetchAll(PDO::FETCH_NUM); + switch($dbh->getAttribute(PDO::ATTR_DRIVER_NAME)) { + case 'mysql': + $list = $dbh->query($subquery)->fetchAll(PDO::FETCH_COLUMN); + $subquery = implode(', ', $list); + break; + case 'pgsql': + $subquery = 'SELECT doctrine_subquery_alias.' . $table->getIdentifier(). ' FROM (' . $subquery . ') AS doctrine_subquery_alias'; + break; } $field = $table->getTableName().'.'.$table->getIdentifier(); - array_unshift($this->parts['where'], $field.' IN ('.$subquery.')'); + array_unshift($this->parts['where'], $field. ' IN (' . $subquery . ')'); $modifyLimit = false; } } @@ -550,7 +556,7 @@ class Doctrine_Query extends Doctrine_Hydrate implements Countable { $subquery .= ( ! empty($this->parts['groupby']))? ' GROUP BY ' . implode(', ',$this->parts['groupby']):''; $subquery .= ( ! empty($this->parts['having']))? ' HAVING ' . implode(' ',$this->parts['having']):''; $subquery .= ( ! empty($this->parts['orderby']))? ' ORDER BY ' . implode(' ', $this->parts['orderby']):''; - + // add driver specific limit clause $subquery = $this->connection->modifyLimitQuery($subquery, $this->parts['limit'], $this->parts['offset']); diff --git a/tests/run.php b/tests/run.php index 8c1fb6442..483b85fe2 100644 --- a/tests/run.php +++ b/tests/run.php @@ -63,7 +63,7 @@ error_reporting(E_ALL); print '
';
 
 $test = new GroupTest('Doctrine Framework Unit Tests');
-/**
+
 $test->addTestCase(new Doctrine_DataDict_Pgsql_TestCase());
 
 $test->addTestCase(new Doctrine_Relation_TestCase());
@@ -147,7 +147,7 @@ $test->addTestCase(new Doctrine_Query_Select_TestCase());
 $test->addTestCase(new Doctrine_Query_Delete_TestCase());
 
 $test->addTestCase(new Doctrine_Query_Update_TestCase());
-*/
+
                                                              
 $test->addTestCase(new Doctrine_Query_Limit_TestCase());