Commit 53bdc31a authored by zYne's avatar zYne

added adapter skeletons, fixed wrong limit subquery ordering

parent b014566e
<?php
/*
* $Id$
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL. For more information, see
* <http://www.phpdoctrine.com>.
*/
/**
* 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();
}
<?php
/*
* $Id$
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*
* This software consists of voluntary contributions made by many individuals
* and is licensed under the LGPL. For more information, see
* <http://www.phpdoctrine.com>.
*/
/**
* 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(){
}
}
......@@ -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);
......
......@@ -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']);
......
<?php
class Doctrine_DataDict_Pgsql_TestCase extends Doctrine_UnitTestCase {
public function prepareTables() { }
public function prepareData() { }
public function getDeclaration($type) {
return $this->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));
}
}
......@@ -63,7 +63,7 @@ error_reporting(E_ALL);
print '<pre>';
$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());
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment