diff --git a/classes/DB.class.php b/classes/DB.class.php index df5305d3a..e81d017a5 100644 --- a/classes/DB.class.php +++ b/classes/DB.class.php @@ -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; } diff --git a/classes/DQL/Parser.class.php b/classes/DQL/Parser.class.php index 9887b0760..3077de70f 100644 --- a/classes/DQL/Parser.class.php +++ b/classes/DQL/Parser.class.php @@ -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; diff --git a/classes/Record.class.php b/classes/Record.class.php index 5794d4afd..7dbb14475 100644 --- a/classes/Record.class.php +++ b/classes/Record.class.php @@ -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); } /** diff --git a/classes/Session/Common.class.php b/classes/Session/Common.class.php index 4cd8d0bd0..f6111422d 100644 --- a/classes/Session/Common.class.php +++ b/classes/Session/Common.class.php @@ -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; } } ?> diff --git a/classes/Validator/Ip.class.php b/classes/Validator/Ip.class.php index 4767aaad2..2f7add1ce 100644 --- a/classes/Validator/Ip.class.php +++ b/classes/Validator/Ip.class.php @@ -1,5 +1,5 @@ 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'])); } + } ?> diff --git a/tests/run.php b/tests/run.php index 95c50f979..b6c03dd68 100644 --- a/tests/run.php +++ b/tests/run.php @@ -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());