mirror of
https://github.com/yiisoft/yii2.git
synced 2025-11-19 07:50:39 +08:00
Fixes #9790: Fixed yii\db\sqlite\QueryBuilder to generate proper SQL for UNION
This commit is contained in:
@@ -24,6 +24,7 @@ Yii Framework 2 Change Log
|
||||
- Bug #9707: Fixed Memcache duration which exceeds 30 days (vernik91)
|
||||
- Bug #9714: Fixed `yii\rbac\PhpManager::updateItem()` unable to save users assignments (rezident1307)
|
||||
- Bug #9754: Fixed `yii\web\Request` error when path info is empty (dynasource)
|
||||
- Bug #9790: Fixed `yii\db\sqlite\QueryBuilder` to generate proper SQL for UNION (romeOz, samdark)
|
||||
- Bug #9791: Fixed endless loop on file creation for non-existing device letters on windows (lukos, cebe)
|
||||
- Bug #9874: Fixed outputting exception stacktrace in non-debug mode when `Response::FORMAT_RAW` is used (nainoon)
|
||||
- Bug #9883: Passing a single `yii\db\Expression` to `Query::select()` or `::addSelect()` was not handled correctly in all cases (cebe)
|
||||
|
||||
@@ -356,4 +356,56 @@ class QueryBuilder extends \yii\db\QueryBuilder
|
||||
|
||||
return '(' . implode($operator === 'IN' ? ' OR ' : ' AND ', $vss) . ')';
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function build($query, $params = [])
|
||||
{
|
||||
$query = $query->prepare($this);
|
||||
|
||||
$params = empty($params) ? $query->params : array_merge($params, $query->params);
|
||||
|
||||
$clauses = [
|
||||
$this->buildSelect($query->select, $params, $query->distinct, $query->selectOption),
|
||||
$this->buildFrom($query->from, $params),
|
||||
$this->buildJoin($query->join, $params),
|
||||
$this->buildWhere($query->where, $params),
|
||||
$this->buildGroupBy($query->groupBy),
|
||||
$this->buildHaving($query->having, $params),
|
||||
];
|
||||
|
||||
$sql = implode($this->separator, array_filter($clauses));
|
||||
$sql = $this->buildOrderByAndLimit($sql, $query->orderBy, $query->limit, $query->offset);
|
||||
|
||||
$union = $this->buildUnion($query->union, $params);
|
||||
if ($union !== '') {
|
||||
$sql = "$sql{$this->separator}$union";
|
||||
}
|
||||
|
||||
return [$sql, $params];
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function buildUnion($unions, &$params)
|
||||
{
|
||||
if (empty($unions)) {
|
||||
return '';
|
||||
}
|
||||
|
||||
$result = '';
|
||||
|
||||
foreach ($unions as $i => $union) {
|
||||
$query = $union['query'];
|
||||
if ($query instanceof Query) {
|
||||
list($unions[$i]['query'], $params) = $this->build($query, $params);
|
||||
}
|
||||
|
||||
$result .= ' UNION ' . ($union['all'] ? 'ALL ' : '') . ' ' . $unions[$i]['query'];
|
||||
}
|
||||
|
||||
return trim($result);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user