From 4bafcc5b317a1feb8f05febf7985d8cfd87d31d7 Mon Sep 17 00:00:00 2001 From: Raymond Kolbe Date: Tue, 9 Apr 2013 17:30:54 -0300 Subject: [PATCH] Fix Oracle subquery ordering MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit See http://www.doctrine-project.org/jira/browse/DDC-1800 and http://www.doctrine-project.org/jira/browse/DDC-1958#comment-19969 --- .../Pagination/LimitSubqueryOutputWalker.php | 23 ++++++++----------- 1 file changed, 9 insertions(+), 14 deletions(-) diff --git a/lib/Doctrine/ORM/Tools/Pagination/LimitSubqueryOutputWalker.php b/lib/Doctrine/ORM/Tools/Pagination/LimitSubqueryOutputWalker.php index 274dac2712e..a6c24ee348d 100644 --- a/lib/Doctrine/ORM/Tools/Pagination/LimitSubqueryOutputWalker.php +++ b/lib/Doctrine/ORM/Tools/Pagination/LimitSubqueryOutputWalker.php @@ -16,6 +16,7 @@ use Doctrine\ORM\Query\SqlWalker; use Doctrine\ORM\Query\AST\SelectStatement; use Doctrine\DBAL\Platforms\PostgreSqlPlatform; +use Doctrine\DBAL\Platforms\OraclePlatform; /** * Wraps the query in order to select root entity IDs for pagination. @@ -138,19 +139,13 @@ public function walkSelectStatement(SelectStatement $AST) } // Build the counter query - if ($this->platform instanceof OraclePlatform) { - // Ordering is lost in Oracle with subqueries - // http://www.doctrine-project.org/jira/browse/DDC-1800 - $sql = sprintf('SELECT DISTINCT %s, ROWNUM FROM (%s) dctrn_result ORDER BY ROWNUM ASC', - implode(', ', $sqlIdentifier), $innerSql); - } else { - $sql = sprintf('SELECT DISTINCT %s FROM (%s) dctrn_result', - implode(', ', $sqlIdentifier), $innerSql); - } + $sql = sprintf('SELECT DISTINCT %s FROM (%s) dctrn_result', + implode(', ', $sqlIdentifier), $innerSql); - if ($this->platform instanceof PostgreSqlPlatform) { + if ($this->platform instanceof PostgreSqlPlatform || + $this->platform instanceof OraclePlatform) { //http://www.doctrine-project.org/jira/browse/DDC-1958 - $this->getPostgresqlSql($AST, $sqlIdentifier, $innerSql, $sql); + $this->preserveSqlOrdering($AST, $sqlIdentifier, $innerSql, $sql); } // Apply the limit and offset. @@ -168,9 +163,9 @@ public function walkSelectStatement(SelectStatement $AST) return $sql; } - + /** - * Generates new SQL for postgresql if necessary. + * Generates new SQL for Postgresql or Oracle if necessary. * * @param SelectStatement $AST * @param array $sqlIdentifier @@ -179,7 +174,7 @@ public function walkSelectStatement(SelectStatement $AST) * * @return void */ - public function getPostgresqlSql(SelectStatement $AST, array $sqlIdentifier, $innerSql, &$sql) + public function preserveSqlOrdering(SelectStatement $AST, array $sqlIdentifier, $innerSql, &$sql) { // For every order by, find out the SQL alias by inspecting the ResultSetMapping. $sqlOrderColumns = array();