@@ -100,9 +100,9 @@ public function walkSelectStatement(SelectStatement $AST)
100100 $ hiddens [$ idx ] = $ expr ->hiddenAliasResultVariable ;
101101 $ expr ->hiddenAliasResultVariable = false ;
102102 }
103-
103+
104104 $ innerSql = parent ::walkSelectStatement ($ AST );
105-
105+
106106 // Restore hiddens
107107 foreach ($ AST ->selectClause ->selectExpressions as $ idx => $ expr ) {
108108 $ expr ->hiddenAliasResultVariable = $ hiddens [$ idx ];
@@ -164,11 +164,8 @@ public function walkSelectStatement(SelectStatement $AST)
164164 $ sql = sprintf ('SELECT DISTINCT %s FROM (%s) dctrn_result ' ,
165165 implode (', ' , $ sqlIdentifier ), $ innerSql );
166166
167- if ($ this ->platform instanceof PostgreSqlPlatform ||
168- $ this ->platform instanceof OraclePlatform) {
169- // http://www.doctrine-project.org/jira/browse/DDC-1958
170- $ this ->preserveSqlOrdering ($ AST , $ sqlIdentifier , $ innerSql , $ sql );
171- }
167+ // http://www.doctrine-project.org/jira/browse/DDC-1958
168+ $ sql = $ this ->preserveSqlOrdering ($ AST , $ sqlIdentifier , $ innerSql , $ sql );
172169
173170 // Apply the limit and offset.
174171 $ sql = $ this ->platform ->modifyLimitQuery (
@@ -185,7 +182,7 @@ public function walkSelectStatement(SelectStatement $AST)
185182
186183 return $ sql ;
187184 }
188-
185+
189186 /**
190187 * Generates new SQL for Postgresql or Oracle if necessary.
191188 *
@@ -196,7 +193,7 @@ public function walkSelectStatement(SelectStatement $AST)
196193 *
197194 * @return void
198195 */
199- public function preserveSqlOrdering (SelectStatement $ AST , array $ sqlIdentifier , $ innerSql , & $ sql )
196+ public function preserveSqlOrdering (SelectStatement $ AST , array $ sqlIdentifier , $ innerSql , $ sql )
200197 {
201198 // For every order by, find out the SQL alias by inspecting the ResultSetMapping.
202199 $ sqlOrderColumns = array ();
@@ -219,11 +216,6 @@ public function preserveSqlOrdering(SelectStatement $AST, array $sqlIdentifier,
219216 $ sqlOrderColumns = array_diff ($ sqlOrderColumns , $ sqlIdentifier );
220217 }
221218
222- // We don't need orderBy in inner query.
223- // However at least on 5.4.6 I'm getting a segmentation fault and thus we don't clear it for now.
224- /*$AST->orderByClause = null;
225- $innerSql = parent::walkSelectStatement($AST);*/
226-
227219 if (count ($ orderBy )) {
228220 $ sql = sprintf (
229221 'SELECT DISTINCT %s FROM (%s) dctrn_result ORDER BY %s ' ,
@@ -232,5 +224,7 @@ public function preserveSqlOrdering(SelectStatement $AST, array $sqlIdentifier,
232224 implode (', ' , $ orderBy )
233225 );
234226 }
227+
228+ return $ sql ;
235229 }
236230}
0 commit comments