From 53bdc31ad51ce13ff05757f1648a92f75b684dca Mon Sep 17 00:00:00 2001 From: zYne Date: Thu, 26 Oct 2006 22:12:58 +0000 Subject: [PATCH] added adapter skeletons, fixed wrong limit subquery ordering --- lib/Doctrine/Adapter/Interface.php | 39 +++++++++++++++++++++++++ lib/Doctrine/Adapter/Statement.php | 47 ++++++++++++++++++++++++++++++ lib/Doctrine/Hydrate.php | 7 +++-- lib/Doctrine/Query.php | 10 ++++--- tests/DataDict/PgsqlTestCase.php | 30 +++++++++++++++++++ tests/DataDict/SqliteTestCase.php | 3 ++ tests/run.php | 8 ++--- 7 files changed, 133 insertions(+), 11 deletions(-) create mode 100644 lib/Doctrine/Adapter/Interface.php create mode 100644 lib/Doctrine/Adapter/Statement.php create mode 100644 tests/DataDict/PgsqlTestCase.php create mode 100644 tests/DataDict/SqliteTestCase.php diff --git a/lib/Doctrine/Adapter/Interface.php b/lib/Doctrine/Adapter/Interface.php new file mode 100644 index 000000000..ccb54591b --- /dev/null +++ b/lib/Doctrine/Adapter/Interface.php @@ -0,0 +1,39 @@ +. + */ +/** + * Doctrine_Adapter_Interface + * + * @author Konsta Vesterinen + * @license LGPL + * @package Doctrine + */ +interface Doctrine_Adapter_Interface { + public function prepare($prepareString); + public function query($queryString); + public function quote($input); + public function exec($statement); + public function lastInsertId(); + public function beginTransaction(); + public function commit(); + public function rollBack(); + public function errorCode(); + public function errorInfo(); +} diff --git a/lib/Doctrine/Adapter/Statement.php b/lib/Doctrine/Adapter/Statement.php new file mode 100644 index 000000000..6a5efcbbf --- /dev/null +++ b/lib/Doctrine/Adapter/Statement.php @@ -0,0 +1,47 @@ +. + */ +/** + * Doctrine_Adapter_Statement + * + * @author Konsta Vesterinen + * @license LGPL + * @package Doctrine + */ +abstract class Doctrine_Adapter_Statement { + public function bindValue($no, $value) { + } + public function fetch() { + } + public function nextRowset() { + } + public function execute() { + } + public function errorCode() { + } + public function errorInfo() { + } + public function rowCount() { + } + public function setFetchMode($mode) { + } + public function columnCount(){ + } +} diff --git a/lib/Doctrine/Hydrate.php b/lib/Doctrine/Hydrate.php index 908ce514a..fd02a3df2 100644 --- a/lib/Doctrine/Hydrate.php +++ b/lib/Doctrine/Hydrate.php @@ -329,14 +329,15 @@ abstract class Doctrine_Hydrate extends Doctrine_Access { array_walk($params, array(__CLASS__, 'convertBoolean')); if( ! $this->view) - $query = $this->getQuery(); + $query = $this->getQuery(true); else $query = $this->view->getSelectSql(); - if($this->isLimitSubqueryUsed()) + if($this->isLimitSubqueryUsed() && + $this->connection->getDBH()->getAttribute(PDO::ATTR_DRIVER_NAME) !== 'mysql') $params = array_merge($params, $params); - $stmt = $this->connection->execute($query,$params); + $stmt = $this->connection->execute($query, $params); if($this->aggregate) return $stmt->fetchAll(PDO::FETCH_ASSOC); diff --git a/lib/Doctrine/Query.php b/lib/Doctrine/Query.php index 38aa63f23..c1505ad3c 100644 --- a/lib/Doctrine/Query.php +++ b/lib/Doctrine/Query.php @@ -438,7 +438,7 @@ class Doctrine_Query extends Doctrine_Hydrate implements Countable { * * @return string */ - public function getQuery() { + public function getQuery($executeSubquery = false) { if(empty($this->parts["select"]) || empty($this->parts["from"])) return false; @@ -488,8 +488,9 @@ 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') { } - //$dbh->query(); + if($dbh->getAttribute(PDO::ATTR_DRIVER_NAME) == 'mysql') { + $list = $dbh->query($subquery)->fetchAll(PDO::FETCH_NUM); + } $field = $table->getTableName().'.'.$table->getIdentifier(); array_unshift($this->parts['where'], $field.' IN ('.$subquery.')'); @@ -548,7 +549,8 @@ class Doctrine_Query extends Doctrine_Hydrate implements Countable { $subquery .= ( ! empty($this->parts['where']))? ' WHERE ' . implode(' AND ',$this->parts['where']):''; $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/DataDict/PgsqlTestCase.php b/tests/DataDict/PgsqlTestCase.php new file mode 100644 index 000000000..6c0f6297b --- /dev/null +++ b/tests/DataDict/PgsqlTestCase.php @@ -0,0 +1,30 @@ +dict->getDoctrineDeclaration(array('type' => $type, 'name' => 'colname', 'length' => 2, 'fixed' => true)); + } + public function testGetDoctrineDefinition() { + $this->dict = new Doctrine_DataDict_Pgsql(); + + $this->assertEqual($this->getDeclaration('smallint'), array(array('integer', 'boolean'), 2, false, null)); + $this->assertEqual($this->getDeclaration('int2'), array(array('integer', 'boolean'), 2, false, null)); + + $this->assertEqual($this->getDeclaration('int'), array(array('integer'), 4, false, null)); + $this->assertEqual($this->getDeclaration('int4'), array(array('integer'), 4, false, null)); + $this->assertEqual($this->getDeclaration('integer'), array(array('integer'), 4, false, null)); + $this->assertEqual($this->getDeclaration('serial'), array(array('integer'), 4, false, null)); + $this->assertEqual($this->getDeclaration('serial4'), array(array('integer'), 4, false, null)); + + + $this->assertEqual($this->getDeclaration('bigint'), array(array('integer'), 8, false, null)); + $this->assertEqual($this->getDeclaration('int8'), array(array('integer'), 8, false, null)); + $this->assertEqual($this->getDeclaration('bigserial'), array(array('integer'), 8, false, null)); + $this->assertEqual($this->getDeclaration('serial8'), array(array('integer'), 8, false, null)); + + $this->assertEqual($this->getDeclaration('bool'), array(array('boolean'), 1, false, null)); + $this->assertEqual($this->getDeclaration('boolean'), array(array('boolean'), 1, false, null)); + + } +} diff --git a/tests/DataDict/SqliteTestCase.php b/tests/DataDict/SqliteTestCase.php new file mode 100644 index 000000000..791a01bbb --- /dev/null +++ b/tests/DataDict/SqliteTestCase.php @@ -0,0 +1,3 @@ + diff --git a/tests/run.php b/tests/run.php index ff75c8d26..8c1fb6442 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());
@@ -129,8 +129,6 @@ $test->addTestCase(new Doctrine_CustomResultSetOrderTestCase());
 $test->addTestCase(new Doctrine_BooleanTestCase());
 
 $test->addTestCase(new Doctrine_Record_Filter_TestCase());
-                                                             
-$test->addTestCase(new Doctrine_Query_Limit_TestCase());
 
 $test->addTestCase(new Doctrine_Query_Condition_TestCase());
 
@@ -149,7 +147,9 @@ $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());
 
 $test->addTestCase(new Doctrine_EnumTestCase());