From 0c9a898ccd805e126efef7a8c62110eb23ca006d Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Fri, 5 Dec 2014 17:09:59 +0100 Subject: [PATCH 1/4] DDC-3434 - removed unneeded escaping sequences --- .../ORM/Tools/Pagination/LimitSubqueryOutputWalkerTest.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Doctrine/Tests/ORM/Tools/Pagination/LimitSubqueryOutputWalkerTest.php b/tests/Doctrine/Tests/ORM/Tools/Pagination/LimitSubqueryOutputWalkerTest.php index e7c5ae2b640..78d8f762699 100644 --- a/tests/Doctrine/Tests/ORM/Tools/Pagination/LimitSubqueryOutputWalkerTest.php +++ b/tests/Doctrine/Tests/ORM/Tools/Pagination/LimitSubqueryOutputWalkerTest.php @@ -200,7 +200,7 @@ public function testCountQueryMixedResultsWithName() 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()); From 6e8057b6ea664ec04c6f64219557237e82227ca2 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Fri, 5 Dec 2014 17:10:39 +0100 Subject: [PATCH 2/4] DDC-3434 - adding test case for `HIDDEN` modifier fields in `ORDER BY` sequences: should be preserved in any case --- .../LimitSubqueryOutputWalkerTest.php | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/tests/Doctrine/Tests/ORM/Tools/Pagination/LimitSubqueryOutputWalkerTest.php b/tests/Doctrine/Tests/ORM/Tools/Pagination/LimitSubqueryOutputWalkerTest.php index 78d8f762699..a012d45df25 100644 --- a/tests/Doctrine/Tests/ORM/Tools/Pagination/LimitSubqueryOutputWalkerTest.php +++ b/tests/Doctrine/Tests/ORM/Tools/Pagination/LimitSubqueryOutputWalkerTest.php @@ -211,5 +211,22 @@ public function testCountQueryWithArithmeticOrderByCondition() $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 id_0, name_2 FROM (SELECT a0_.id AS id_0, a0_.name AS name_1, a0_.name AS name_2 FROM Author a0_ ORDER BY name_2 DESC) dctrn_result ORDER BY name_2 DESC', + $query->getSql() + ); + } } From 6169175a89eabe8620c2a88cf908211f51b4a7c3 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Fri, 5 Dec 2014 17:11:57 +0100 Subject: [PATCH 3/4] DDC-3434 - `HIDDEN` modifier marked fields in `ORDER BY` clause are always preserved when creating a paginator subquery --- .../Pagination/LimitSubqueryOutputWalker.php | 28 ++++++++----------- 1 file changed, 12 insertions(+), 16 deletions(-) diff --git a/lib/Doctrine/ORM/Tools/Pagination/LimitSubqueryOutputWalker.php b/lib/Doctrine/ORM/Tools/Pagination/LimitSubqueryOutputWalker.php index a37ab5645af..9b1753b51fc 100644 --- a/lib/Doctrine/ORM/Tools/Pagination/LimitSubqueryOutputWalker.php +++ b/lib/Doctrine/ORM/Tools/Pagination/LimitSubqueryOutputWalker.php @@ -92,25 +92,21 @@ public function __construct($query, $parserResult, array $queryComponents) */ 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; - } - - $innerSql = parent::walkSelectStatement($AST); + // Set every select expression as visible(hidden = false) to + // make $AST to have scalar mappings properly + $hiddens = array(); - // 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 From ac67a10d4c2a488d67e93d0029d554b110887be6 Mon Sep 17 00:00:00 2001 From: Marco Pivetta Date: Fri, 5 Dec 2014 18:02:12 +0100 Subject: [PATCH 4/4] DDC-3434 - adding note on why restoring 'HIDDEN' selected fields is relevant --- .../ORM/Tools/Pagination/LimitSubqueryOutputWalker.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/lib/Doctrine/ORM/Tools/Pagination/LimitSubqueryOutputWalker.php b/lib/Doctrine/ORM/Tools/Pagination/LimitSubqueryOutputWalker.php index 9b1753b51fc..338920b2ef0 100644 --- a/lib/Doctrine/ORM/Tools/Pagination/LimitSubqueryOutputWalker.php +++ b/lib/Doctrine/ORM/Tools/Pagination/LimitSubqueryOutputWalker.php @@ -93,7 +93,8 @@ public function __construct($query, $parserResult, array $queryComponents) public function walkSelectStatement(SelectStatement $AST) { // Set every select expression as visible(hidden = false) to - // make $AST to have scalar mappings properly + // 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(); foreach ($AST->selectClause->selectExpressions as $idx => $expr) {