Commit ff0aad6b authored by doctrine's avatar doctrine

Limit offset support fixed

parent be1d5f16
...@@ -65,8 +65,8 @@ class Doctrine_DB extends PDO implements Countable, IteratorAggregate { ...@@ -65,8 +65,8 @@ class Doctrine_DB extends PDO implements Countable, IteratorAggregate {
public function query($query) { public function query($query) {
$this->queries[] = $query; $this->queries[] = $query;
$time = microtime(); $time = microtime();
$stmt = parent::query($query); $stmt = parent::query($query);
$this->exectimes[] = (microtime() - $time); $this->exectimes[] = (microtime() - $time);
return $stmt; return $stmt;
} }
......
...@@ -128,6 +128,18 @@ class Doctrine_DQL_Parser { ...@@ -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 * @return string the built sql query
*/ */
...@@ -153,6 +165,9 @@ class Doctrine_DQL_Parser { ...@@ -153,6 +165,9 @@ class Doctrine_DQL_Parser {
if( ! empty($this->orderby)) if( ! empty($this->orderby))
$q .= " ORDER BY ".implode(", ",$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; return $q;
} }
/** /**
...@@ -182,7 +197,7 @@ class Doctrine_DQL_Parser { ...@@ -182,7 +197,7 @@ class Doctrine_DQL_Parser {
if( ! empty($this->orderby)) if( ! empty($this->orderby))
$q .= " ORDER BY ".implode(", ",$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); $q = $this->session->modifyLimitQuery($q,$this->limit,$this->offset);
return $q; return $q;
......
...@@ -732,7 +732,7 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite ...@@ -732,7 +732,7 @@ abstract class Doctrine_Record extends Doctrine_Access implements Countable, Ite
* returns a copy of this object * returns a copy of this object
* @return DAO * @return DAO
*/ */
final public function copy() { public function copy() {
return $this->table->create($this->data); return $this->table->create($this->data);
} }
/** /**
......
...@@ -3,8 +3,16 @@ ...@@ -3,8 +3,16 @@
* standard session, the parent of pgsql, mysql and sqlite * standard session, the parent of pgsql, mysql and sqlite
*/ */
class Doctrine_Session_Common extends Doctrine_Session { class Doctrine_Session_Common extends Doctrine_Session {
public function modifyLimitQuery($query,$limit,$offset) { public function modifyLimitQuery($query,$limit = null,$offset = null) {
return $query." LIMIT ".$limit." OFFSET ".$offset; if(isset($limit))
$query .= " LIMIT ".$limit;
else
$query .= " LIMIT 99999999999999";
if(isset($offset))
$query .= " OFFSET ".$offset;
return $query;
} }
} }
?> ?>
<?php <?php
class Doctrine_Validator_IP { class Doctrine_Validator_Ip {
/** /**
* @param Doctrine_Record $record * @param Doctrine_Record $record
* @param string $key * @param string $key
......
<?php <?php
require_once("UnitTestCase.class.php"); require_once("UnitTestCase.class.php");
class Doctrine_DQL_ParserTestCase extends Doctrine_UnitTestCase { 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() { public function testPrepared() {
$coll = $this->session->query("FROM User WHERE User.name = :name", array(":name" => "zYne")); $coll = $this->session->query("FROM User WHERE User.name = :name", array(":name" => "zYne"));
$this->assertEqual($coll->count(), 1); $this->assertEqual($coll->count(), 1);
} }
public function testQuery() { public function testQuery() {
$graph = new Doctrine_DQL_Parser($this->session); $graph = new Doctrine_DQL_Parser($this->session);
...@@ -191,5 +206,6 @@ class Doctrine_DQL_ParserTestCase extends Doctrine_UnitTestCase { ...@@ -191,5 +206,6 @@ class Doctrine_DQL_ParserTestCase extends Doctrine_UnitTestCase {
$this->assertTrue(isset($values['users'])); $this->assertTrue(isset($values['users']));
$this->assertTrue(isset($values['max'])); $this->assertTrue(isset($values['max']));
} }
} }
?> ?>
...@@ -23,7 +23,7 @@ $test = new GroupTest("Doctrine Framework Unit Tests"); ...@@ -23,7 +23,7 @@ $test = new GroupTest("Doctrine Framework Unit Tests");
/**
$test->addTestCase(new Doctrine_RecordTestCase()); $test->addTestCase(new Doctrine_RecordTestCase());
$test->addTestCase(new Doctrine_SessionTestCase()); $test->addTestCase(new Doctrine_SessionTestCase());
...@@ -36,10 +36,10 @@ $test->addTestCase(new Doctrine_AccessTestCase()); ...@@ -36,10 +36,10 @@ $test->addTestCase(new Doctrine_AccessTestCase());
$test->addTestCase(new Doctrine_ConfigurableTestCase()); $test->addTestCase(new Doctrine_ConfigurableTestCase());
$test->addTestCase(new Doctrine_EventListenerTestCase()); $test->addTestCase(new Doctrine_EventListenerTestCase());
*/
$test->addTestCase(new Doctrine_DQL_ParserTestCase()); $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_FileTestCase());
//$test->addTestCase(new Doctrine_Cache_SqliteTestCase()); //$test->addTestCase(new Doctrine_Cache_SqliteTestCase());
......
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