Fixes #3752: QueryBuilder::batchInsert() does not typecast input values

This commit is contained in:
Qiang Xue
2014-06-09 08:12:08 -04:00
parent de8ba90019
commit ce49416e32
3 changed files with 9 additions and 8 deletions

View File

@ -40,6 +40,7 @@ Yii Framework 2 Change Log
- Bug #3601: Fixed the bug that the refresh URL was not generated correctly by `Captcha` (qiangxue, klevron) - Bug #3601: Fixed the bug that the refresh URL was not generated correctly by `Captcha` (qiangxue, klevron)
- Bug #3715: Fixed the bug that using a custom pager/sorter with `GridView` may generate two different pagers/sorters if the layout configures two pagers/sorters (qiangxue) - Bug #3715: Fixed the bug that using a custom pager/sorter with `GridView` may generate two different pagers/sorters if the layout configures two pagers/sorters (qiangxue)
- Bug #3716: `DynamicModel::validateData()` does not call `validate()` if the `$rules` parameter is empty (qiangxue) - Bug #3716: `DynamicModel::validateData()` does not call `validate()` if the `$rules` parameter is empty (qiangxue)
- Bug #3752: `QueryBuilder::batchInsert()` does not typecast input values (qiangxue)
- Bug: Fixed inconsistent return of `\yii\console\Application::runAction()` (samdark) - Bug: Fixed inconsistent return of `\yii\console\Application::runAction()` (samdark)
- Bug: URL encoding for the route parameter added to `\yii\web\UrlManager` (klimov-paul) - Bug: URL encoding for the route parameter added to `\yii\web\UrlManager` (klimov-paul)
- Bug: Fixed the bug that requesting protected or private action methods would cause 500 error instead of 404 (qiangxue) - Bug: Fixed the bug that requesting protected or private action methods would cause 500 error instead of 404 (qiangxue)

View File

@ -183,10 +183,6 @@ class QueryBuilder extends \yii\base\Object
$columnSchemas = []; $columnSchemas = [];
} }
foreach ($columns as $i => $name) {
$columns[$i] = $this->db->quoteColumnName($name);
}
$values = []; $values = [];
foreach ($rows as $row) { foreach ($rows as $row) {
$vs = []; $vs = [];
@ -206,6 +202,10 @@ class QueryBuilder extends \yii\base\Object
$values[] = '(' . implode(', ', $vs) . ')'; $values[] = '(' . implode(', ', $vs) . ')';
} }
foreach ($columns as $i => $name) {
$columns[$i] = $this->db->quoteColumnName($name);
}
return 'INSERT INTO ' . $this->db->quoteTableName($table) return 'INSERT INTO ' . $this->db->quoteTableName($table)
. ' (' . implode(', ', $columns) . ') VALUES ' . implode(', ', $values); . ' (' . implode(', ', $columns) . ') VALUES ' . implode(', ', $values);
} }

View File

@ -68,10 +68,6 @@ class QueryBuilder extends \yii\db\QueryBuilder
$columnSchemas = []; $columnSchemas = [];
} }
foreach ($columns as $i => $name) {
$columns[$i] = $this->db->quoteColumnName($name);
}
$values = []; $values = [];
foreach ($rows as $row) { foreach ($rows as $row) {
$vs = []; $vs = [];
@ -91,6 +87,10 @@ class QueryBuilder extends \yii\db\QueryBuilder
$values[] = implode(', ', $vs); $values[] = implode(', ', $vs);
} }
foreach ($columns as $i => $name) {
$columns[$i] = $this->db->quoteColumnName($name);
}
return 'INSERT INTO ' . $this->db->quoteTableName($table) return 'INSERT INTO ' . $this->db->quoteTableName($table)
. ' (' . implode(', ', $columns) . ') SELECT ' . implode(' UNION SELECT ', $values); . ' (' . implode(', ', $columns) . ') SELECT ' . implode(' UNION SELECT ', $values);
} }