1
0
mirror of synced 2024-12-05 03:06:05 +03:00

Limit offset support fixed

This commit is contained in:
doctrine 2006-04-15 20:03:12 +00:00
parent be1d5f168e
commit ff0aad6ba0
7 changed files with 48 additions and 9 deletions

View File

@ -65,8 +65,8 @@ class Doctrine_DB extends PDO implements Countable, IteratorAggregate {
public function query($query) {
$this->queries[] = $query;
$time = microtime();
$stmt = parent::query($query);
$this->exectimes[] = (microtime() - $time);
return $stmt;
}

View File

@ -128,6 +128,18 @@ class Doctrine_DQL_Parser {
}
}
}
/**
* @return integer
*/
final public function getLimit() {
return $this->limit;
}
/**
* @return integer
*/
final public function getOffset() {
return $this->offset;
}
/**
* @return string the built sql query
*/
@ -153,6 +165,9 @@ class Doctrine_DQL_Parser {
if( ! empty($this->orderby))
$q .= " ORDER BY ".implode(", ",$this->orderby);
if( ! empty($this->limit) || ! empty($this->offset))
$q = $this->session->modifyLimitQuery($q,$this->limit,$this->offset);
return $q;
}
/**
@ -182,7 +197,7 @@ class Doctrine_DQL_Parser {
if( ! empty($this->orderby))
$q .= " ORDER BY ".implode(", ",$this->orderby);
if( ! empty($this->limit) AND ! empty($this->offset))
if( ! empty($this->limit) && ! empty($this->offset))
$q = $this->session->modifyLimitQuery($q,$this->limit,$this->offset);
return $q;

View File

@ -732,7 +732,7 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
* returns a copy of this object
* @return DAO
*/
final public function copy() {
public function copy() {
return $this->table->create($this->data);
}
/**

View File

@ -3,8 +3,16 @@
* standard session, the parent of pgsql, mysql and sqlite
*/
class Doctrine_Session_Common extends Doctrine_Session {
public function modifyLimitQuery($query,$limit,$offset) {
return $query." LIMIT ".$limit." OFFSET ".$offset;
public function modifyLimitQuery($query,$limit = null,$offset = null) {
if(isset($limit))
$query .= " LIMIT ".$limit;
else
$query .= " LIMIT 99999999999999";
if(isset($offset))
$query .= " OFFSET ".$offset;
return $query;
}
}
?>

View File

@ -1,5 +1,5 @@
<?php
class Doctrine_Validator_IP {
class Doctrine_Validator_Ip {
/**
* @param Doctrine_Record $record
* @param string $key

View File

@ -1,10 +1,25 @@
<?php
require_once("UnitTestCase.class.php");
class Doctrine_DQL_ParserTestCase extends Doctrine_UnitTestCase {
public function testLimit() {
$graph = new Doctrine_DQL_Parser($this->session);
$coll = $graph->query("FROM User LIMIT 3");
$this->assertEqual($graph->getLimit(), 3);
$this->assertEqual($coll->count(), 3);
}
public function testOffset() {
$graph = new Doctrine_DQL_Parser($this->session);
$coll = $graph->query("FROM User LIMIT 3 OFFSET 3");
$this->assertEqual($graph->getOffset(), 3);
$this->assertEqual($coll->count(), 3);
}
public function testPrepared() {
$coll = $this->session->query("FROM User WHERE User.name = :name", array(":name" => "zYne"));
$this->assertEqual($coll->count(), 1);
}
public function testQuery() {
$graph = new Doctrine_DQL_Parser($this->session);
@ -191,5 +206,6 @@ class Doctrine_DQL_ParserTestCase extends Doctrine_UnitTestCase {
$this->assertTrue(isset($values['users']));
$this->assertTrue(isset($values['max']));
}
}
?>

View File

@ -23,7 +23,7 @@ $test = new GroupTest("Doctrine Framework Unit Tests");
/**
$test->addTestCase(new Doctrine_RecordTestCase());
$test->addTestCase(new Doctrine_SessionTestCase());
@ -36,10 +36,10 @@ $test->addTestCase(new Doctrine_AccessTestCase());
$test->addTestCase(new Doctrine_ConfigurableTestCase());
$test->addTestCase(new Doctrine_EventListenerTestCase());
*/
$test->addTestCase(new Doctrine_DQL_ParserTestCase());
$test->addTestCase(new Doctrine_BatchIteratorTestCase());
//$test->addTestCase(new Doctrine_BatchIteratorTestCase());
//$test->addTestCase(new Doctrine_Cache_FileTestCase());
//$test->addTestCase(new Doctrine_Cache_SqliteTestCase());