Commit 9ff8b0f9 by Qiang Xue

Fixes #2571: Fixed the bug that batchInsert will fail for SQLite if the values…

Fixes #2571: Fixed the bug that batchInsert will fail for SQLite if the values contain null or boolean false; Fixes #2683: Fixed the bug that batchInsert will fail for MySQL if the values contain boolean false.
parent 7c520248
...@@ -50,10 +50,12 @@ Yii Framework 2 Change Log ...@@ -50,10 +50,12 @@ Yii Framework 2 Change Log
- Bug #2519: MessageSource removed translation messages when event handler was bound to `missingTranslation`-event (cebe) - Bug #2519: MessageSource removed translation messages when event handler was bound to `missingTranslation`-event (cebe)
- Bug #2527: Source language for `app` message category was always `en` no matter which application `sourceLanguage` was used (samdark) - Bug #2527: Source language for `app` message category was always `en` no matter which application `sourceLanguage` was used (samdark)
- Bug #2559: Going back on browser history breaks GridView filtering with `Pjax` (tonydspaniard) - Bug #2559: Going back on browser history breaks GridView filtering with `Pjax` (tonydspaniard)
- Bug #2571: Fixed the bug that batchInsert will fail for SQLite if the values contain null or boolean false (qiangxue)
- Bug #2607: `yii message` tool wasn't updating `message` table (mitalcoi) - Bug #2607: `yii message` tool wasn't updating `message` table (mitalcoi)
- Bug #2624: Html::textArea() should respect "name" option. (qiangxue) - Bug #2624: Html::textArea() should respect "name" option. (qiangxue)
- Bug #2653: Fixed the bug that unsetting an unpopulated AR relation would trigger exception (qiangxue) - Bug #2653: Fixed the bug that unsetting an unpopulated AR relation would trigger exception (qiangxue)
- Bug #2681: Fixed the bug of php build-in server https://bugs.php.net/bug.php?id=66606 (dizews) - Bug #2681: Fixed the bug of php build-in server https://bugs.php.net/bug.php?id=66606 (dizews)
- Bug #2683: Fixed the bug that batchInsert will fail for MySQL if the values contain boolean false (qiangxue)
- Bug #2695: Fixed the issue that `FileValidator::isEmpty()` always returns true for validate multiple files (ZhandosKz) - Bug #2695: Fixed the issue that `FileValidator::isEmpty()` always returns true for validate multiple files (ZhandosKz)
- Bug #2739: Fixed the issue that `CreateAction::run()` was using obsolete `Controller::createAbsoluteUrl()` method (tonydspaniard) - Bug #2739: Fixed the issue that `CreateAction::run()` was using obsolete `Controller::createAbsoluteUrl()` method (tonydspaniard)
- 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)
......
...@@ -177,7 +177,14 @@ class QueryBuilder extends \yii\base\Object ...@@ -177,7 +177,14 @@ class QueryBuilder extends \yii\base\Object
if (!is_array($value) && isset($columnSchemas[$columns[$i]])) { if (!is_array($value) && isset($columnSchemas[$columns[$i]])) {
$value = $columnSchemas[$columns[$i]]->typecast($value); $value = $columnSchemas[$columns[$i]]->typecast($value);
} }
$vs[] = is_string($value) ? $this->db->quoteValue($value) : ($value === null ? 'NULL' : $value); if (is_string($value)) {
$value = $this->db->quoteValue($value);
} elseif ($value === false) {
$value = 0;
} elseif ($value === null) {
$value = 'NULL';
}
$vs[] = $value;
} }
$values[] = '(' . implode(', ', $vs) . ')'; $values[] = '(' . implode(', ', $vs) . ')';
} }
......
...@@ -79,7 +79,14 @@ class QueryBuilder extends \yii\db\QueryBuilder ...@@ -79,7 +79,14 @@ class QueryBuilder extends \yii\db\QueryBuilder
if (!is_array($value) && isset($columnSchemas[$columns[$i]])) { if (!is_array($value) && isset($columnSchemas[$columns[$i]])) {
$value = $columnSchemas[$columns[$i]]->typecast($value); $value = $columnSchemas[$columns[$i]]->typecast($value);
} }
$vs[] = is_string($value) ? $this->db->quoteValue($value) : $value; if (is_string($value)) {
$value = $this->db->quoteValue($value);
} elseif ($value === false) {
$value = 0;
} elseif ($value === null) {
$value = 'NULL';
}
$vs[] = $value;
} }
$values[] = implode(', ', $vs); $values[] = implode(', ', $vs);
} }
......
...@@ -216,6 +216,18 @@ class CommandTest extends DatabaseTestCase ...@@ -216,6 +216,18 @@ class CommandTest extends DatabaseTestCase
$this->assertTrue(is_array($result) && isset($result[0])); $this->assertTrue(is_array($result) && isset($result[0]));
} }
public function testBatchInsert()
{
$command = $this->getConnection()->createCommand();
$command->batchInsert('tbl_customer',
['email', 'name', 'address'], [
['t1@example.com', 't1', 't1 address'],
['t2@example.com', null, false],
]
);
$this->assertEquals(2, $command->execute());
}
public function testInsert() public function testInsert()
{ {
} }
......
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