mirror of
https://github.com/yiisoft/yii2.git
synced 2025-11-15 22:09:48 +08:00
Update QueryBuilder.php
Change using of implode to convert array of queries to union to array_reduce. Result of this changing is that code feel difference between two selects that connects with UNION and two selects that connects with UNION ALL.
This commit is contained in:
@@ -739,6 +739,20 @@ class QueryBuilder extends \yii\base\Object
|
|||||||
if (empty($unions)) {
|
if (empty($unions)) {
|
||||||
return '';
|
return '';
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $left left element of reducing pair
|
||||||
|
* @param string $right right element of reducing pair
|
||||||
|
* @return string imploding pair with "UNION ALL" if
|
||||||
|
* right element is array and "UNION" if not
|
||||||
|
*/
|
||||||
|
$reducer = function($left, $right)
|
||||||
|
{
|
||||||
|
if($all = is_array($right))
|
||||||
|
list ($right) = $right;
|
||||||
|
return $left . ' UNION ' . ($all ? 'ALL ' : ' ') . $right . ' ) ';
|
||||||
|
}
|
||||||
|
|
||||||
foreach ($unions as $i => $union) {
|
foreach ($unions as $i => $union) {
|
||||||
if ($union instanceof Query) {
|
if ($union instanceof Query) {
|
||||||
// save the original parameters so that we can restore them later to prevent from modifying the query object
|
// save the original parameters so that we can restore them later to prevent from modifying the query object
|
||||||
@@ -748,7 +762,7 @@ class QueryBuilder extends \yii\base\Object
|
|||||||
$union->params = $originalParams;
|
$union->params = $originalParams;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return "UNION (\n" . implode("\n) UNION (\n", $unions) . "\n)";
|
return array_reduce($unions, $reducer);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|||||||
Reference in New Issue
Block a user