DDC-980 - Fix Update and Delete statements reference of the root table when doing subselects.
This commit is contained in:
parent
7a2c99353a
commit
078e19d1c7
@ -209,9 +209,13 @@ class SqlWalker implements TreeWalker
|
||||
*
|
||||
* @param string $tableName
|
||||
* @param string $alias
|
||||
* @param string $dqlAlias
|
||||
* @return string
|
||||
*/
|
||||
public function setSqlTableAlias($tableName, $alias)
|
||||
public function setSqlTableAlias($tableName, $alias, $dqlAlias = '')
|
||||
{
|
||||
$tableName .= $dqlAlias;
|
||||
|
||||
$this->_tableAliasMap[$tableName] = $alias;
|
||||
|
||||
return $alias;
|
||||
@ -1260,9 +1264,7 @@ class SqlWalker implements TreeWalker
|
||||
$class = $this->_em->getClassMetadata($deleteClause->abstractSchemaName);
|
||||
$sql .= $class->getQuotedTableName($this->_platform);
|
||||
|
||||
if ($this->_useSqlTableAliases) {
|
||||
$sql .= ' ' . $this->getSqlTableAlias($class->getTableName());
|
||||
}
|
||||
$this->setSqlTableAlias($class->getTableName(), $class->getTableName(), $deleteClause->aliasIdentificationVariable);
|
||||
|
||||
$this->_rootAliases[] = $deleteClause->aliasIdentificationVariable;
|
||||
|
||||
@ -1281,9 +1283,7 @@ class SqlWalker implements TreeWalker
|
||||
$class = $this->_em->getClassMetadata($updateClause->abstractSchemaName);
|
||||
$sql .= $class->getQuotedTableName($this->_platform);
|
||||
|
||||
if ($this->_useSqlTableAliases) {
|
||||
$sql .= ' ' . $this->getSqlTableAlias($class->getTableName());
|
||||
}
|
||||
$this->setSqlTableAlias($class->getTableName(), $class->getTableName(), $updateClause->aliasIdentificationVariable);
|
||||
|
||||
$this->_rootAliases[] = $updateClause->aliasIdentificationVariable;
|
||||
|
||||
|
@ -299,4 +299,13 @@ class ManyToManyBasicAssociationTest extends \Doctrine\Tests\OrmFunctionalTestCa
|
||||
|
||||
return $user;
|
||||
}
|
||||
|
||||
/**
|
||||
* @group DDC-980
|
||||
*/
|
||||
public function testUpdateDeleteSizeSubselectQueries()
|
||||
{
|
||||
$this->_em->createQuery("DELETE Doctrine\Tests\Models\CMS\CmsUser u WHERE SIZE(u.groups) = 10")->execute();
|
||||
$this->_em->createQuery("UPDATE Doctrine\Tests\Models\CMS\CmsUser u SET u.status = 'inactive' WHERE SIZE(u.groups) = 10")->execute();
|
||||
}
|
||||
}
|
||||
|
@ -273,4 +273,15 @@ class DeleteSqlGenerationTest extends \Doctrine\Tests\OrmTestCase
|
||||
'DELETE FROM cms_users WHERE id NOT IN (?, ?)'
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group DDC-980
|
||||
*/
|
||||
public function testSubselectTableAliasReferencing()
|
||||
{
|
||||
$this->assertSqlGeneration(
|
||||
'DELETE Doctrine\Tests\Models\CMS\CmsUser u WHERE SIZE(u.groups) = 10',
|
||||
'DELETE FROM cms_users WHERE (SELECT COUNT(*) FROM cms_users_groups c0_ WHERE c0_.user_id = cms_users.id) = 10'
|
||||
);
|
||||
}
|
||||
}
|
||||
|
@ -6,43 +6,43 @@ use Doctrine\ORM\Query\ParserResult;
|
||||
|
||||
class ParserResultTest extends \PHPUnit_Framework_TestCase
|
||||
{
|
||||
public $result;
|
||||
public $parserResult;
|
||||
|
||||
public function setUp()
|
||||
{
|
||||
$this->result = new ParserResult();
|
||||
$this->parserResult = new ParserResult();
|
||||
}
|
||||
|
||||
public function testGetRsm()
|
||||
{
|
||||
$this->assertType(
|
||||
'Doctrine\ORM\Query\ResultSetMapping',
|
||||
$this->result->getResultSetMapping()
|
||||
$this->parserResult->getResultSetMapping()
|
||||
);
|
||||
}
|
||||
|
||||
public function testSetGetSqlExecutor()
|
||||
{
|
||||
$this->assertNull($this->result->getSqlExecutor());
|
||||
$this->assertNull($this->parserResult->getSqlExecutor());
|
||||
|
||||
$executor = $this->getMock('Doctrine\ORM\Query\Exec\AbstractSqlExecutor', array('execute'));
|
||||
$this->result->setSqlExecutor($executor);
|
||||
$this->assertSame($executor, $this->result->getSqlExecutor());
|
||||
$this->parserResult->setSqlExecutor($executor);
|
||||
$this->assertSame($executor, $this->parserResult->getSqlExecutor());
|
||||
}
|
||||
|
||||
public function testGetSqlParameterPosition()
|
||||
{
|
||||
$this->result->addParameterMapping(1, 1);
|
||||
$this->result->addParameterMapping(1, 2);
|
||||
$this->assertEquals(array(1, 2), $this->result->getSqlParameterPositions(1));
|
||||
$this->parserResult->addParameterMapping(1, 1);
|
||||
$this->parserResult->addParameterMapping(1, 2);
|
||||
$this->assertEquals(array(1, 2), $this->parserResult->getSqlParameterPositions(1));
|
||||
}
|
||||
|
||||
public function testGetParameterMappings()
|
||||
{
|
||||
$this->assertType('array', $this->result->getParameterMappings());
|
||||
$this->assertType('array', $this->parserResult->getParameterMappings());
|
||||
|
||||
$this->result->addParameterMapping(1, 1);
|
||||
$this->result->addParameterMapping(1, 2);
|
||||
$this->assertEquals(array(1 => array(1, 2)), $this->result->getParameterMappings());
|
||||
$this->parserResult->addParameterMapping(1, 1);
|
||||
$this->parserResult->addParameterMapping(1, 2);
|
||||
$this->assertEquals(array(1 => array(1, 2)), $this->parserResult->getParameterMappings());
|
||||
}
|
||||
}
|
@ -175,4 +175,15 @@ class UpdateSqlGenerationTest extends \Doctrine\Tests\OrmTestCase
|
||||
"UPDATE cms_comments SET article_id = NULL WHERE article_id = ?"
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @group DDC-980
|
||||
*/
|
||||
public function testSubselectTableAliasReferencing()
|
||||
{
|
||||
$this->assertSqlGeneration(
|
||||
"UPDATE Doctrine\Tests\Models\CMS\CmsUser u SET u.status = 'inactive' WHERE SIZE(u.groups) = 10",
|
||||
"UPDATE cms_users SET status = 'inactive' WHERE (SELECT COUNT(*) FROM cms_users_groups c0_ WHERE c0_.user_id = cms_users.id) = 10"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user