1
0
mirror of synced 2025-02-02 13:31:45 +03:00

Merge branch 'hotfix/#1211-DDC-3434-backport-to-2.4' into 2.4

Close #1211
This commit is contained in:
Marco Pivetta 2014-12-05 18:11:57 +01:00
commit f45cf2629e
2 changed files with 31 additions and 17 deletions

View File

@ -93,25 +93,22 @@ class LimitSubqueryOutputWalker extends SqlWalker
*/
public function walkSelectStatement(SelectStatement $AST)
{
if ($this->platform instanceof PostgreSqlPlatform) {
// Set every select expression as visible(hidden = false) to
// make $AST to have scalar mappings properly
$hiddens = array();
foreach ($AST->selectClause->selectExpressions as $idx => $expr) {
$hiddens[$idx] = $expr->hiddenAliasResultVariable;
$expr->hiddenAliasResultVariable = false;
}
// Set every select expression as visible(hidden = false) to
// make $AST have scalar mappings properly - this is relevant for referencing selected
// fields from outside the subquery, for example in the ORDER BY segment
$hiddens = array();
$innerSql = parent::walkSelectStatement($AST);
// Restore hiddens
foreach ($AST->selectClause->selectExpressions as $idx => $expr) {
$expr->hiddenAliasResultVariable = $hiddens[$idx];
}
} else {
$innerSql = parent::walkSelectStatement($AST);
foreach ($AST->selectClause->selectExpressions as $idx => $expr) {
$hiddens[$idx] = $expr->hiddenAliasResultVariable;
$expr->hiddenAliasResultVariable = false;
}
$innerSql = parent::walkSelectStatement($AST);
// Restore hiddens
foreach ($AST->selectClause->selectExpressions as $idx => $expr) {
$expr->hiddenAliasResultVariable = $hiddens[$idx];
}
// Find out the SQL alias of the identifier column of the root entity.
// It may be possible to make this work with multiple root entities but that

View File

@ -200,7 +200,7 @@ class LimitSubqueryOutputWalkerTest extends PaginationTestCase
public function testCountQueryWithArithmeticOrderByCondition()
{
$query = $this->entityManager->createQuery(
'SELECT a FROM Doctrine\\Tests\\ORM\\Tools\\Pagination\\Author a ORDER BY (1 - 1000) * 1 DESC'
'SELECT a FROM Doctrine\Tests\ORM\Tools\Pagination\Author a ORDER BY (1 - 1000) * 1 DESC'
);
$this->entityManager->getConnection()->setDatabasePlatform(new MySqlPlatform());
@ -211,5 +211,22 @@ class LimitSubqueryOutputWalkerTest extends PaginationTestCase
$query->getSQL()
);
}
/**
* @group DDC-3434
*/
public function testLimitSubqueryWithHiddenSelectionInOrderBy()
{
$query = $this->entityManager->createQuery(
'SELECT a, a.name AS HIDDEN ord FROM Doctrine\Tests\ORM\Tools\Pagination\Author a ORDER BY ord DESC'
);
$query->setHint(Query::HINT_CUSTOM_OUTPUT_WALKER, 'Doctrine\ORM\Tools\Pagination\LimitSubqueryOutputWalker');
$this->assertEquals(
'SELECT DISTINCT id0, name2 FROM (SELECT a0_.id AS id0, a0_.name AS name1, a0_.name AS name2 FROM Author a0_ ORDER BY name2 DESC) dctrn_result ORDER BY name2 DESC',
$query->getSql()
);
}
}