mirror of
https://github.com/yiisoft/yii2.git
synced 2025-11-22 01:30:23 +08:00
fix issue with postgreSQL and batch inserting boolean values
fixes #4654
This commit is contained in:
@@ -80,6 +80,7 @@ Yii Framework 2 Change Log
|
||||
- Bug #4514: Fixed Request class crashing when empty CSRF token value is sent in cookie (cebe)
|
||||
- Bug #4519: `yii\base\Model::isAttributeRequired()` should check if the `when` option of the validator is set (thiagotalma)
|
||||
- Bug #4592: Fixed `yii help` command was listing incorrect action names for methods like `actionSayNO` (samdark)
|
||||
- Bug #4654: Fixed issue with PostgreSQL and inserting boolean values with batch insert (cebe)
|
||||
- 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: Fixed the bug that requesting protected or private action methods would cause 500 error instead of 404 (qiangxue)
|
||||
|
||||
@@ -84,11 +84,13 @@ abstract class Schema extends Object
|
||||
*/
|
||||
private $_builder;
|
||||
|
||||
|
||||
/**
|
||||
* @return \yii\db\ColumnSchema
|
||||
* @throws \yii\base\InvalidConfigException
|
||||
*/
|
||||
protected function createColumnSchema() {
|
||||
protected function createColumnSchema()
|
||||
{
|
||||
return Yii::createObject('yii\db\ColumnSchema');
|
||||
}
|
||||
|
||||
|
||||
@@ -159,4 +159,44 @@ class QueryBuilder extends \yii\db\QueryBuilder
|
||||
. $this->db->quoteColumnName($column) . ' TYPE '
|
||||
. $this->getColumnType($type);
|
||||
}
|
||||
|
||||
/**
|
||||
* @inheritdoc
|
||||
*/
|
||||
public function batchInsert($table, $columns, $rows)
|
||||
{
|
||||
if (($tableSchema = $this->db->getTableSchema($table)) !== null) {
|
||||
$columnSchemas = $tableSchema->columns;
|
||||
} else {
|
||||
$columnSchemas = [];
|
||||
}
|
||||
|
||||
$values = [];
|
||||
foreach ($rows as $row) {
|
||||
$vs = [];
|
||||
foreach ($row as $i => $value) {
|
||||
if (!is_array($value) && isset($columnSchemas[$columns[$i]])) {
|
||||
$value = $columnSchemas[$columns[$i]]->dbTypecast($value);
|
||||
}
|
||||
if (is_string($value)) {
|
||||
$value = $this->db->quoteValue($value);
|
||||
} elseif ($value === true) {
|
||||
$value = 'TRUE';
|
||||
} elseif ($value === false) {
|
||||
$value = 'FALSE';
|
||||
} elseif ($value === null) {
|
||||
$value = 'NULL';
|
||||
}
|
||||
$vs[] = $value;
|
||||
}
|
||||
$values[] = '(' . implode(', ', $vs) . ')';
|
||||
}
|
||||
|
||||
foreach ($columns as $i => $name) {
|
||||
$columns[$i] = $this->db->quoteColumnName($name);
|
||||
}
|
||||
|
||||
return 'INSERT INTO ' . $this->db->quoteTableName($table)
|
||||
. ' (' . implode(', ', $columns) . ') VALUES ' . implode(', ', $values);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user