Commit 8053082e by Qiang Xue

Fixes #2848: Individual queries should be enclosed within parenthesis in a UNION query

parent 7f6f3f6f
...@@ -61,6 +61,7 @@ Yii Framework 2 Change Log ...@@ -61,6 +61,7 @@ Yii Framework 2 Change Log
- Bug #2740: Fixed the issue that `CaptchaAction::run()` was using obsolete `Controller::createUrl()` method (tonydspaniard) - Bug #2740: Fixed the issue that `CaptchaAction::run()` was using obsolete `Controller::createUrl()` method (tonydspaniard)
- Bug #2760: Fixed GridView `filterUrl` parameters (qiangxue, AlexGx) - Bug #2760: Fixed GridView `filterUrl` parameters (qiangxue, AlexGx)
- Bug #2834: When overriding i18n translation sources from config using `app*` or `yii*` default `app` and `yii` sources were not removed (samdark) - Bug #2834: When overriding i18n translation sources from config using `app*` or `yii*` default `app` and `yii` sources were not removed (samdark)
- Bug #2848: Individual queries should be enclosed within parenthesis in a UNION query (qiangxue)
- Bug: Fixed `Call to a member function registerAssetFiles() on a non-object` in case of wrong `sourcePath` for an asset bundle (samdark) - Bug: Fixed `Call to a member function registerAssetFiles() on a non-object` in case of wrong `sourcePath` for an asset bundle (samdark)
- Bug: Fixed incorrect event name for `yii\jui\Spinner` (samdark) - Bug: Fixed incorrect event name for `yii\jui\Spinner` (samdark)
- Bug: Json::encode() did not handle objects that implement JsonSerializable interface correctly (cebe) - Bug: Json::encode() did not handle objects that implement JsonSerializable interface correctly (cebe)
......
...@@ -87,10 +87,16 @@ class QueryBuilder extends \yii\base\Object ...@@ -87,10 +87,16 @@ class QueryBuilder extends \yii\base\Object
$this->buildHaving($query->having, $params), $this->buildHaving($query->having, $params),
$this->buildOrderBy($query->orderBy), $this->buildOrderBy($query->orderBy),
$this->buildLimit($query->limit, $query->offset), $this->buildLimit($query->limit, $query->offset),
$this->buildUnion($query->union, $params),
]; ];
return [implode($this->separator, array_filter($clauses)), $params]; $sql = implode($this->separator, array_filter($clauses));
$union = $this->buildUnion($query->union, $params);
if ($union !== '') {
$sql = "($sql){$this->separator}$union";
}
return [$sql, $params];
} }
/** /**
......
...@@ -40,9 +40,9 @@ class QueryBuilder extends \yii\db\QueryBuilder ...@@ -40,9 +40,9 @@ class QueryBuilder extends \yii\db\QueryBuilder
$this->sql = $this->buildLimit($query->limit, $query->offset); $this->sql = $this->buildLimit($query->limit, $query->offset);
$unions = $this->buildUnion($query->union, $params); $union = $this->buildUnion($query->union, $params);
if ($unions !== '') { if ($union !== '') {
$this->sql .= $this->separator . $unions; $this->sql = "{$this->sql}{$this->separator}$union";
} }
return [$this->sql, $params]; return [$this->sql, $params];
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment