1
0
mirror of synced 2025-01-20 23:41:39 +03:00

Merge branch 'DDC-980'

This commit is contained in:
Benjamin Eberlei 2011-01-13 21:16:24 +01:00
commit fdee7a9ae0
5 changed files with 51 additions and 20 deletions

View File

@ -209,9 +209,13 @@ class SqlWalker implements TreeWalker
* *
* @param string $tableName * @param string $tableName
* @param string $alias * @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; $this->_tableAliasMap[$tableName] = $alias;
return $alias; return $alias;
@ -1260,9 +1264,7 @@ class SqlWalker implements TreeWalker
$class = $this->_em->getClassMetadata($deleteClause->abstractSchemaName); $class = $this->_em->getClassMetadata($deleteClause->abstractSchemaName);
$sql .= $class->getQuotedTableName($this->_platform); $sql .= $class->getQuotedTableName($this->_platform);
if ($this->_useSqlTableAliases) { $this->setSqlTableAlias($class->getTableName(), $class->getTableName(), $deleteClause->aliasIdentificationVariable);
$sql .= ' ' . $this->getSqlTableAlias($class->getTableName());
}
$this->_rootAliases[] = $deleteClause->aliasIdentificationVariable; $this->_rootAliases[] = $deleteClause->aliasIdentificationVariable;
@ -1281,9 +1283,7 @@ class SqlWalker implements TreeWalker
$class = $this->_em->getClassMetadata($updateClause->abstractSchemaName); $class = $this->_em->getClassMetadata($updateClause->abstractSchemaName);
$sql .= $class->getQuotedTableName($this->_platform); $sql .= $class->getQuotedTableName($this->_platform);
if ($this->_useSqlTableAliases) { $this->setSqlTableAlias($class->getTableName(), $class->getTableName(), $updateClause->aliasIdentificationVariable);
$sql .= ' ' . $this->getSqlTableAlias($class->getTableName());
}
$this->_rootAliases[] = $updateClause->aliasIdentificationVariable; $this->_rootAliases[] = $updateClause->aliasIdentificationVariable;

View File

@ -299,4 +299,13 @@ class ManyToManyBasicAssociationTest extends \Doctrine\Tests\OrmFunctionalTestCa
return $user; 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();
}
} }

View File

@ -273,4 +273,15 @@ class DeleteSqlGenerationTest extends \Doctrine\Tests\OrmTestCase
'DELETE FROM cms_users WHERE id NOT IN (?, ?)' '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'
);
}
} }

View File

@ -6,43 +6,43 @@ use Doctrine\ORM\Query\ParserResult;
class ParserResultTest extends \PHPUnit_Framework_TestCase class ParserResultTest extends \PHPUnit_Framework_TestCase
{ {
public $result; public $parserResult;
public function setUp() public function setUp()
{ {
$this->result = new ParserResult(); $this->parserResult = new ParserResult();
} }
public function testGetRsm() public function testGetRsm()
{ {
$this->assertType( $this->assertType(
'Doctrine\ORM\Query\ResultSetMapping', 'Doctrine\ORM\Query\ResultSetMapping',
$this->result->getResultSetMapping() $this->parserResult->getResultSetMapping()
); );
} }
public function testSetGetSqlExecutor() public function testSetGetSqlExecutor()
{ {
$this->assertNull($this->result->getSqlExecutor()); $this->assertNull($this->parserResult->getSqlExecutor());
$executor = $this->getMock('Doctrine\ORM\Query\Exec\AbstractSqlExecutor', array('execute')); $executor = $this->getMock('Doctrine\ORM\Query\Exec\AbstractSqlExecutor', array('execute'));
$this->result->setSqlExecutor($executor); $this->parserResult->setSqlExecutor($executor);
$this->assertSame($executor, $this->result->getSqlExecutor()); $this->assertSame($executor, $this->parserResult->getSqlExecutor());
} }
public function testGetSqlParameterPosition() public function testGetSqlParameterPosition()
{ {
$this->result->addParameterMapping(1, 1); $this->parserResult->addParameterMapping(1, 1);
$this->result->addParameterMapping(1, 2); $this->parserResult->addParameterMapping(1, 2);
$this->assertEquals(array(1, 2), $this->result->getSqlParameterPositions(1)); $this->assertEquals(array(1, 2), $this->parserResult->getSqlParameterPositions(1));
} }
public function testGetParameterMappings() public function testGetParameterMappings()
{ {
$this->assertType('array', $this->result->getParameterMappings()); $this->assertType('array', $this->parserResult->getParameterMappings());
$this->result->addParameterMapping(1, 1); $this->parserResult->addParameterMapping(1, 1);
$this->result->addParameterMapping(1, 2); $this->parserResult->addParameterMapping(1, 2);
$this->assertEquals(array(1 => array(1, 2)), $this->result->getParameterMappings()); $this->assertEquals(array(1 => array(1, 2)), $this->parserResult->getParameterMappings());
} }
} }

View File

@ -175,4 +175,15 @@ class UpdateSqlGenerationTest extends \Doctrine\Tests\OrmTestCase
"UPDATE cms_comments SET article_id = NULL WHERE article_id = ?" "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"
);
}
} }