mirror of
https://github.com/yiisoft/yii2.git
synced 2025-08-14 22:30:27 +08:00
Fixes #13418: Fixed QueryBuilder::batchInsert()
if $rows is \Generator
This commit is contained in:
@ -11,6 +11,7 @@ Yii Framework 2 Change Log
|
||||
- Bug #13306: Wildcard in `reloadableScripts` in `yii.js` allows 0 characters (arogachev)
|
||||
- Bug #13340: Fixed `yii\db\Connection::useMaster()` - Exception within callback completely disables slaves (Vovan-VE)
|
||||
- Bug #13343: Fixed `yii\i18n\Formatter::asTime()` to process time-only values without time zone conversion (bizley)
|
||||
- Bug #13418: Fixed `QueryBuilder::batchInsert()` if $rows is `\Generator` (lav45)
|
||||
- Bug #13494: Fixed `yii\console\controllers\MessageConstroller::saveMessagesToDb()` to work on different DBMS correctly (silverfire)
|
||||
- Bug #13513: Fixed RBAC migration to work correctly on Oracle DBMS (silverfire)
|
||||
- Bug #13537: Fixed `yii\web\CacheSession::destroySession()` to work correctly when session is not written yet (silverfire, papalapa)
|
||||
|
@ -268,6 +268,9 @@ class QueryBuilder extends \yii\base\Object
|
||||
}
|
||||
$values[] = '(' . implode(', ', $vs) . ')';
|
||||
}
|
||||
if (empty($values)) {
|
||||
return '';
|
||||
}
|
||||
|
||||
foreach ($columns as $i => $name) {
|
||||
$columns[$i] = $schema->quoteColumnName($name);
|
||||
|
@ -262,6 +262,9 @@ EOD;
|
||||
}
|
||||
$values[] = '(' . implode(', ', $vs) . ')';
|
||||
}
|
||||
if (empty($values)) {
|
||||
return '';
|
||||
}
|
||||
|
||||
foreach ($columns as $i => $name) {
|
||||
$columns[$i] = $schema->quoteColumnName($name);
|
||||
|
@ -316,6 +316,9 @@ class QueryBuilder extends \yii\db\QueryBuilder
|
||||
}
|
||||
$values[] = '(' . implode(', ', $vs) . ')';
|
||||
}
|
||||
if (empty($values)) {
|
||||
return '';
|
||||
}
|
||||
|
||||
foreach ($columns as $i => $name) {
|
||||
$columns[$i] = $schema->quoteColumnName($name);
|
||||
|
@ -106,6 +106,9 @@ class QueryBuilder extends \yii\db\QueryBuilder
|
||||
}
|
||||
$values[] = implode(', ', $vs);
|
||||
}
|
||||
if (empty($values)) {
|
||||
return '';
|
||||
}
|
||||
|
||||
foreach ($columns as $i => $name) {
|
||||
$columns[$i] = $schema->quoteColumnName($name);
|
||||
|
@ -298,6 +298,15 @@ SQL;
|
||||
$this->assertEquals(0, $command->execute());
|
||||
}
|
||||
|
||||
public function testBatchInsertWithYield()
|
||||
{
|
||||
if (version_compare(PHP_VERSION, '5.5', '<')) {
|
||||
$this->markTestSkipped('The yield function is only supported with php 5.5 =< version');
|
||||
} else {
|
||||
include __DIR__ . '/testBatchInsertWithYield.php';
|
||||
}
|
||||
}
|
||||
|
||||
public function testInsert()
|
||||
{
|
||||
$db = $this->getConnection();
|
||||
@ -559,7 +568,6 @@ SQL;
|
||||
], $records);
|
||||
}
|
||||
|
||||
|
||||
public function testDropTable()
|
||||
{
|
||||
$db = $this->getConnection();
|
||||
|
18
tests/framework/db/testBatchInsertWithYield.php
Normal file
18
tests/framework/db/testBatchInsertWithYield.php
Normal file
@ -0,0 +1,18 @@
|
||||
<?php
|
||||
/**
|
||||
* @var $this \yiiunit\framework\db\CommandTest
|
||||
*/
|
||||
|
||||
$rows = call_user_func(function () {
|
||||
if (false) {
|
||||
yield [];
|
||||
}
|
||||
});
|
||||
|
||||
$command = $this->getConnection()->createCommand();
|
||||
$command->batchInsert(
|
||||
'{{customer}}',
|
||||
['email', 'name', 'address'],
|
||||
$rows
|
||||
);
|
||||
$this->assertEquals(0, $command->execute());
|
Reference in New Issue
Block a user