Merge pull request #939 from doctrine/DDC-1985
[DDC-2939] Order Preservation
This commit is contained in:
commit
4c4e4f6d3d
1 changed files with 8 additions and 14 deletions
|
@ -100,9 +100,9 @@ class LimitSubqueryOutputWalker extends SqlWalker
|
||||||
$hiddens[$idx] = $expr->hiddenAliasResultVariable;
|
$hiddens[$idx] = $expr->hiddenAliasResultVariable;
|
||||||
$expr->hiddenAliasResultVariable = false;
|
$expr->hiddenAliasResultVariable = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
$innerSql = parent::walkSelectStatement($AST);
|
$innerSql = parent::walkSelectStatement($AST);
|
||||||
|
|
||||||
// Restore hiddens
|
// Restore hiddens
|
||||||
foreach ($AST->selectClause->selectExpressions as $idx => $expr) {
|
foreach ($AST->selectClause->selectExpressions as $idx => $expr) {
|
||||||
$expr->hiddenAliasResultVariable = $hiddens[$idx];
|
$expr->hiddenAliasResultVariable = $hiddens[$idx];
|
||||||
|
@ -164,11 +164,8 @@ class LimitSubqueryOutputWalker extends SqlWalker
|
||||||
$sql = sprintf('SELECT DISTINCT %s FROM (%s) dctrn_result',
|
$sql = sprintf('SELECT DISTINCT %s FROM (%s) dctrn_result',
|
||||||
implode(', ', $sqlIdentifier), $innerSql);
|
implode(', ', $sqlIdentifier), $innerSql);
|
||||||
|
|
||||||
if ($this->platform instanceof PostgreSqlPlatform ||
|
// http://www.doctrine-project.org/jira/browse/DDC-1958
|
||||||
$this->platform instanceof OraclePlatform) {
|
$sql = $this->preserveSqlOrdering($AST, $sqlIdentifier, $innerSql, $sql);
|
||||||
// http://www.doctrine-project.org/jira/browse/DDC-1958
|
|
||||||
$this->preserveSqlOrdering($AST, $sqlIdentifier, $innerSql, $sql);
|
|
||||||
}
|
|
||||||
|
|
||||||
// Apply the limit and offset.
|
// Apply the limit and offset.
|
||||||
$sql = $this->platform->modifyLimitQuery(
|
$sql = $this->platform->modifyLimitQuery(
|
||||||
|
@ -185,7 +182,7 @@ class LimitSubqueryOutputWalker extends SqlWalker
|
||||||
|
|
||||||
return $sql;
|
return $sql;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Generates new SQL for Postgresql or Oracle if necessary.
|
* Generates new SQL for Postgresql or Oracle if necessary.
|
||||||
*
|
*
|
||||||
|
@ -196,7 +193,7 @@ class LimitSubqueryOutputWalker extends SqlWalker
|
||||||
*
|
*
|
||||||
* @return void
|
* @return void
|
||||||
*/
|
*/
|
||||||
public function preserveSqlOrdering(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.
|
// For every order by, find out the SQL alias by inspecting the ResultSetMapping.
|
||||||
$sqlOrderColumns = array();
|
$sqlOrderColumns = array();
|
||||||
|
@ -219,11 +216,6 @@ class LimitSubqueryOutputWalker extends SqlWalker
|
||||||
$sqlOrderColumns = array_diff($sqlOrderColumns, $sqlIdentifier);
|
$sqlOrderColumns = array_diff($sqlOrderColumns, $sqlIdentifier);
|
||||||
}
|
}
|
||||||
|
|
||||||
// We don't need orderBy in inner query.
|
|
||||||
// However at least on 5.4.6 I'm getting a segmentation fault and thus we don't clear it for now.
|
|
||||||
/*$AST->orderByClause = null;
|
|
||||||
$innerSql = parent::walkSelectStatement($AST);*/
|
|
||||||
|
|
||||||
if (count($orderBy)) {
|
if (count($orderBy)) {
|
||||||
$sql = sprintf(
|
$sql = sprintf(
|
||||||
'SELECT DISTINCT %s FROM (%s) dctrn_result ORDER BY %s',
|
'SELECT DISTINCT %s FROM (%s) dctrn_result ORDER BY %s',
|
||||||
|
@ -232,5 +224,7 @@ class LimitSubqueryOutputWalker extends SqlWalker
|
||||||
implode(', ', $orderBy)
|
implode(', ', $orderBy)
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return $sql;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Reference in a new issue