diff --git a/draft/new-core/Hydrate.php b/draft/new-core/Hydrate.php index 14aaa6982..dd7dbaf10 100644 --- a/draft/new-core/Hydrate.php +++ b/draft/new-core/Hydrate.php @@ -162,7 +162,7 @@ class Doctrine_Hydrate2 } $this->parts[$name][] = $part; } - public function getDeclaration($name) + public function getDeclaration($name) { if ( ! isset($this->_aliasMap[$name])) { throw new Doctrine_Hydrate_Exception('Unknown component alias ' . $name); @@ -174,8 +174,13 @@ class Doctrine_Hydrate2 { if ( ! isset($this->parts[$name])) { throw new Doctrine_Hydrate_Exception('Unknown query part ' . $name); + } + + if ($name !== 'limit' && $name !== 'offset') { + $this->parts[$name] = array($part); + } else { + $this->parts[$name] = $part; } - $this->parts[$name] = array($part); } /** * copyAliases @@ -249,16 +254,17 @@ class Doctrine_Hydrate2 { $this->tables = array(); $this->parts = array( - "select" => array(), - "from" => array(), - "join" => array(), - "where" => array(), - "groupby" => array(), - "having" => array(), - "orderby" => array(), - "limit" => false, - "offset" => false, - ); + 'select' => array(), + 'from' => array(), + 'set' => array(), + 'join' => array(), + 'where' => array(), + 'groupby' => array(), + 'having' => array(), + 'orderby' => array(), + 'limit' => false, + 'offset' => false, + ); $this->inheritanceApplied = false; $this->tableAliases = array(); $this->aliasHandler->clear(); diff --git a/draft/new-core/Query.php b/draft/new-core/Query.php index 97ad75c89..7dacfa4dc 100644 --- a/draft/new-core/Query.php +++ b/draft/new-core/Query.php @@ -1144,6 +1144,17 @@ class Doctrine_Query2 extends Doctrine_Hydrate2 implements Countable return $this->getParser('from')->parse($update); } + /** + * set + * sets the SET part of the query + * + * @param string $update DQL UPDATE part + * @return Doctrine_Query + */ + public function set($key, $value) + { + return $this->getParser('set')->parse($key . ' = ' . $value); + } /** * from * sets the FROM part of the query diff --git a/tests/Query/DeleteTestCase.php b/tests/Query/DeleteTestCase.php index 67e207a16..823b343a7 100644 --- a/tests/Query/DeleteTestCase.php +++ b/tests/Query/DeleteTestCase.php @@ -35,13 +35,13 @@ class Doctrine_Query_Delete_TestCase extends Doctrine_UnitTestCase { public function testDeleteAllWithColumnAggregationInheritance() { - $q = new Doctrine_Query(); + $q = new Doctrine_Query2(); $q->parseQuery('DELETE FROM User'); $this->assertEqual($q->getQuery(), 'DELETE FROM entity WHERE (type = 0)'); - $q = new Doctrine_Query(); + $q = new Doctrine_Query2(); $q->delete()->from('User'); @@ -49,13 +49,13 @@ class Doctrine_Query_Delete_TestCase extends Doctrine_UnitTestCase } public function testDeleteAll() { - $q = new Doctrine_Query(); + $q = new Doctrine_Query2(); $q->parseQuery('DELETE FROM Entity'); $this->assertEqual($q->getQuery(), 'DELETE FROM entity'); - $q = new Doctrine_Query(); + $q = new Doctrine_Query2(); $q->delete()->from('Entity'); @@ -63,13 +63,13 @@ class Doctrine_Query_Delete_TestCase extends Doctrine_UnitTestCase } public function testDeleteWithCondition() { - $q = new Doctrine_Query(); + $q = new Doctrine_Query2(); $q->parseQuery('DELETE FROM Entity WHERE id = 3'); $this->assertEqual($q->getQuery(), 'DELETE FROM entity WHERE id = 3'); - $q = new Doctrine_Query(); + $q = new Doctrine_Query2(); $q->delete()->from('Entity')->where('id = 3'); @@ -77,13 +77,13 @@ class Doctrine_Query_Delete_TestCase extends Doctrine_UnitTestCase } public function testDeleteWithLimit() { - $q = new Doctrine_Query(); + $q = new Doctrine_Query2(); $q->parseQuery('DELETE FROM Entity LIMIT 20'); $this->assertEqual($q->getQuery(), 'DELETE FROM entity LIMIT 20'); - $q = new Doctrine_Query(); + $q = new Doctrine_Query2(); $q->delete()->from('Entity')->limit(20); @@ -91,13 +91,13 @@ class Doctrine_Query_Delete_TestCase extends Doctrine_UnitTestCase } public function testDeleteWithLimitAndOffset() { - $q = new Doctrine_Query(); + $q = new Doctrine_Query2(); $q->parseQuery('DELETE FROM Entity LIMIT 10 OFFSET 20'); $this->assertEqual($q->getQuery(), 'DELETE FROM entity LIMIT 10 OFFSET 20'); - $q = new Doctrine_Query(); + $q = new Doctrine_Query2(); $q->delete()->from('Entity')->limit(10)->offset(20); diff --git a/tests/Query/UpdateTestCase.php b/tests/Query/UpdateTestCase.php index ef3f6a42d..10d2b7821 100644 --- a/tests/Query/UpdateTestCase.php +++ b/tests/Query/UpdateTestCase.php @@ -35,13 +35,13 @@ class Doctrine_Query_Update_TestCase extends Doctrine_UnitTestCase { public function testUpdateAllWithColumnAggregationInheritance() { - $q = new Doctrine_Query(); + $q = new Doctrine_Query2(); $q->parseQuery("UPDATE User u SET u.name = 'someone'"); $this->assertEqual($q->getQuery(), "UPDATE entity SET name = 'someone' WHERE (type = 0)"); - $q = new Doctrine_Query(); + $q = new Doctrine_Query2(); $q->update('User u')->set('u.name', "'someone'"); @@ -49,13 +49,13 @@ class Doctrine_Query_Update_TestCase extends Doctrine_UnitTestCase } public function testUpdateWorksWithMultipleColumns() { - $q = new Doctrine_Query(); + $q = new Doctrine_Query2(); $q->parseQuery("UPDATE User u SET u.name = 'someone', u.email_id = 5"); $this->assertEqual($q->getQuery(), "UPDATE entity SET name = 'someone', email_id = 5 WHERE (type = 0)"); - $q = new Doctrine_Query(); + $q = new Doctrine_Query2(); $q->update('User u')->set('u.name', "'someone'")->set('u.email_id', 5); @@ -63,7 +63,7 @@ class Doctrine_Query_Update_TestCase extends Doctrine_UnitTestCase } public function testUpdateSupportsConditions() { - $q = new Doctrine_Query(); + $q = new Doctrine_Query2(); $q->parseQuery("UPDATE User u SET u.name = 'someone' WHERE u.id = 5");