Commit 94b2d170 by Qiang Xue

Fixes issue #460

parent 66e69867
...@@ -150,17 +150,20 @@ class QueryBuilder extends \yii\db\QueryBuilder ...@@ -150,17 +150,20 @@ class QueryBuilder extends \yii\db\QueryBuilder
*/ */
public function batchInsert($table, $columns, $rows) public function batchInsert($table, $columns, $rows)
{ {
foreach ($columns as $i => $name) {
$columns[$i] = $this->db->quoteColumnName($name);
}
$values = array(); $values = array();
foreach ($rows as $row) { foreach ($rows as $row) {
$vs = array(); $vs = array();
foreach ($row as $value) { foreach ($row as $value) {
$vs[] = is_string($value) ? $this->db->quoteValue($value) : $value; $vs[] = is_string($value) ? $this->db->quoteValue($value) : $value;
} }
$values[] = $vs; $values[] = '(' . implode(', ', $vs) . ')';
} }
return 'INSERT INTO ' . $this->db->quoteTableName($table) return 'INSERT INTO ' . $this->db->quoteTableName($table)
. ' (' . implode(', ', $columns) . ') VALUES (' . ' (' . implode(', ', $columns) . ') VALUES ' . implode(', ', $values);
. implode(', ', $values) . ')';
} }
} }
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