Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

## 2.0.0 under development

- Enh #260: Support `Traversable` values for `DMLQueryBuilder::batchInsert()` method with empty columns (@Tigrov)
- Enh #255: Implement `SqlParser` and `ExpressionBuilder` driver classes (@Tigrov)

## 1.3.0 March 21, 2024
Expand Down
4 changes: 4 additions & 0 deletions src/DMLQueryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,10 @@ final class DMLQueryBuilder extends AbstractDMLQueryBuilder
*/
public function batchInsert(string $table, array $columns, iterable $rows, array &$params = []): string
{
if (!is_array($rows)) {
$rows = $this->prepareTraversable($rows);
}

if (empty($rows)) {
return '';
}
Expand Down
2 changes: 1 addition & 1 deletion tests/CommandTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public function testAddDefaultValue(): void
public function testBatchInsert(
string $table,
array $columns,
array $values,
iterable $values,
string $expected,
array $expectedParams = [],
int $insertedRow = 1
Expand Down
5 changes: 4 additions & 1 deletion tests/Provider/CommandProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,10 @@ public static function batchInsert(): array
'empty columns and objects' => [
':qp3' => '1',
],
'empty columns and Traversable' => [
'empty columns and a Traversable value' => [
':qp3' => '1',
],
'empty columns and Traversable values' => [
':qp3' => '1',
],
];
Expand Down