new model now supports DQL DELETEs and UPDATEs
This commit is contained in:
parent
44809328f0
commit
4289bdd9ab
@ -175,7 +175,12 @@ class Doctrine_Hydrate2
|
|||||||
if ( ! isset($this->parts[$name])) {
|
if ( ! isset($this->parts[$name])) {
|
||||||
throw new Doctrine_Hydrate_Exception('Unknown query part ' . $name);
|
throw new Doctrine_Hydrate_Exception('Unknown query part ' . $name);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if ($name !== 'limit' && $name !== 'offset') {
|
||||||
$this->parts[$name] = array($part);
|
$this->parts[$name] = array($part);
|
||||||
|
} else {
|
||||||
|
$this->parts[$name] = $part;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* copyAliases
|
* copyAliases
|
||||||
@ -249,15 +254,16 @@ class Doctrine_Hydrate2
|
|||||||
{
|
{
|
||||||
$this->tables = array();
|
$this->tables = array();
|
||||||
$this->parts = array(
|
$this->parts = array(
|
||||||
"select" => array(),
|
'select' => array(),
|
||||||
"from" => array(),
|
'from' => array(),
|
||||||
"join" => array(),
|
'set' => array(),
|
||||||
"where" => array(),
|
'join' => array(),
|
||||||
"groupby" => array(),
|
'where' => array(),
|
||||||
"having" => array(),
|
'groupby' => array(),
|
||||||
"orderby" => array(),
|
'having' => array(),
|
||||||
"limit" => false,
|
'orderby' => array(),
|
||||||
"offset" => false,
|
'limit' => false,
|
||||||
|
'offset' => false,
|
||||||
);
|
);
|
||||||
$this->inheritanceApplied = false;
|
$this->inheritanceApplied = false;
|
||||||
$this->tableAliases = array();
|
$this->tableAliases = array();
|
||||||
|
@ -1144,6 +1144,17 @@ class Doctrine_Query2 extends Doctrine_Hydrate2 implements Countable
|
|||||||
|
|
||||||
return $this->getParser('from')->parse($update);
|
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
|
* from
|
||||||
* sets the FROM part of the query
|
* sets the FROM part of the query
|
||||||
|
@ -35,13 +35,13 @@ class Doctrine_Query_Delete_TestCase extends Doctrine_UnitTestCase
|
|||||||
{
|
{
|
||||||
public function testDeleteAllWithColumnAggregationInheritance()
|
public function testDeleteAllWithColumnAggregationInheritance()
|
||||||
{
|
{
|
||||||
$q = new Doctrine_Query();
|
$q = new Doctrine_Query2();
|
||||||
|
|
||||||
$q->parseQuery('DELETE FROM User');
|
$q->parseQuery('DELETE FROM User');
|
||||||
|
|
||||||
$this->assertEqual($q->getQuery(), 'DELETE FROM entity WHERE (type = 0)');
|
$this->assertEqual($q->getQuery(), 'DELETE FROM entity WHERE (type = 0)');
|
||||||
|
|
||||||
$q = new Doctrine_Query();
|
$q = new Doctrine_Query2();
|
||||||
|
|
||||||
$q->delete()->from('User');
|
$q->delete()->from('User');
|
||||||
|
|
||||||
@ -49,13 +49,13 @@ class Doctrine_Query_Delete_TestCase extends Doctrine_UnitTestCase
|
|||||||
}
|
}
|
||||||
public function testDeleteAll()
|
public function testDeleteAll()
|
||||||
{
|
{
|
||||||
$q = new Doctrine_Query();
|
$q = new Doctrine_Query2();
|
||||||
|
|
||||||
$q->parseQuery('DELETE FROM Entity');
|
$q->parseQuery('DELETE FROM Entity');
|
||||||
|
|
||||||
$this->assertEqual($q->getQuery(), 'DELETE FROM entity');
|
$this->assertEqual($q->getQuery(), 'DELETE FROM entity');
|
||||||
|
|
||||||
$q = new Doctrine_Query();
|
$q = new Doctrine_Query2();
|
||||||
|
|
||||||
$q->delete()->from('Entity');
|
$q->delete()->from('Entity');
|
||||||
|
|
||||||
@ -63,13 +63,13 @@ class Doctrine_Query_Delete_TestCase extends Doctrine_UnitTestCase
|
|||||||
}
|
}
|
||||||
public function testDeleteWithCondition()
|
public function testDeleteWithCondition()
|
||||||
{
|
{
|
||||||
$q = new Doctrine_Query();
|
$q = new Doctrine_Query2();
|
||||||
|
|
||||||
$q->parseQuery('DELETE FROM Entity WHERE id = 3');
|
$q->parseQuery('DELETE FROM Entity WHERE id = 3');
|
||||||
|
|
||||||
$this->assertEqual($q->getQuery(), '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');
|
$q->delete()->from('Entity')->where('id = 3');
|
||||||
|
|
||||||
@ -77,13 +77,13 @@ class Doctrine_Query_Delete_TestCase extends Doctrine_UnitTestCase
|
|||||||
}
|
}
|
||||||
public function testDeleteWithLimit()
|
public function testDeleteWithLimit()
|
||||||
{
|
{
|
||||||
$q = new Doctrine_Query();
|
$q = new Doctrine_Query2();
|
||||||
|
|
||||||
$q->parseQuery('DELETE FROM Entity LIMIT 20');
|
$q->parseQuery('DELETE FROM Entity LIMIT 20');
|
||||||
|
|
||||||
$this->assertEqual($q->getQuery(), '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);
|
$q->delete()->from('Entity')->limit(20);
|
||||||
|
|
||||||
@ -91,13 +91,13 @@ class Doctrine_Query_Delete_TestCase extends Doctrine_UnitTestCase
|
|||||||
}
|
}
|
||||||
public function testDeleteWithLimitAndOffset()
|
public function testDeleteWithLimitAndOffset()
|
||||||
{
|
{
|
||||||
$q = new Doctrine_Query();
|
$q = new Doctrine_Query2();
|
||||||
|
|
||||||
$q->parseQuery('DELETE FROM Entity LIMIT 10 OFFSET 20');
|
$q->parseQuery('DELETE FROM Entity LIMIT 10 OFFSET 20');
|
||||||
|
|
||||||
$this->assertEqual($q->getQuery(), '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);
|
$q->delete()->from('Entity')->limit(10)->offset(20);
|
||||||
|
|
||||||
|
@ -35,13 +35,13 @@ class Doctrine_Query_Update_TestCase extends Doctrine_UnitTestCase
|
|||||||
{
|
{
|
||||||
public function testUpdateAllWithColumnAggregationInheritance()
|
public function testUpdateAllWithColumnAggregationInheritance()
|
||||||
{
|
{
|
||||||
$q = new Doctrine_Query();
|
$q = new Doctrine_Query2();
|
||||||
|
|
||||||
$q->parseQuery("UPDATE User u SET u.name = 'someone'");
|
$q->parseQuery("UPDATE User u SET u.name = 'someone'");
|
||||||
|
|
||||||
$this->assertEqual($q->getQuery(), "UPDATE entity SET name = 'someone' WHERE (type = 0)");
|
$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'");
|
$q->update('User u')->set('u.name', "'someone'");
|
||||||
|
|
||||||
@ -49,13 +49,13 @@ class Doctrine_Query_Update_TestCase extends Doctrine_UnitTestCase
|
|||||||
}
|
}
|
||||||
public function testUpdateWorksWithMultipleColumns()
|
public function testUpdateWorksWithMultipleColumns()
|
||||||
{
|
{
|
||||||
$q = new Doctrine_Query();
|
$q = new Doctrine_Query2();
|
||||||
|
|
||||||
$q->parseQuery("UPDATE User u SET u.name = 'someone', u.email_id = 5");
|
$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)");
|
$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);
|
$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()
|
public function testUpdateSupportsConditions()
|
||||||
{
|
{
|
||||||
$q = new Doctrine_Query();
|
$q = new Doctrine_Query2();
|
||||||
|
|
||||||
$q->parseQuery("UPDATE User u SET u.name = 'someone' WHERE u.id = 5");
|
$q->parseQuery("UPDATE User u SET u.name = 'someone' WHERE u.id = 5");
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user