From f5179d76892bc5ef62e562e17f0457a7f44afdb1 Mon Sep 17 00:00:00 2001 From: Tigrov Date: Fri, 18 Oct 2024 14:00:07 +0700 Subject: [PATCH 1/3] Update `DMLQueryBuilder::insertBatch()` method --- src/QueryBuilder/AbstractDMLQueryBuilder.php | 4 ++-- tests/Provider/QueryBuilderProvider.php | 4 ++-- tests/Support/DbHelper.php | 13 ++++++++++++- 3 files changed, 16 insertions(+), 5 deletions(-) diff --git a/src/QueryBuilder/AbstractDMLQueryBuilder.php b/src/QueryBuilder/AbstractDMLQueryBuilder.php index 7097b0f4a..3b3905ec1 100644 --- a/src/QueryBuilder/AbstractDMLQueryBuilder.php +++ b/src/QueryBuilder/AbstractDMLQueryBuilder.php @@ -96,7 +96,7 @@ public function insertBatch(string $table, iterable $rows, array $columns = [], $query .= ' (' . implode(', ', $quotedColumnNames) . ')'; } - return $query . ' VALUES ' . implode(', ', $values); + return $query . ' VALUES (' . implode('), (', $values) . ')'; } public function delete(string $table, array|string $condition, array &$params): string @@ -209,7 +209,7 @@ protected function prepareBatchInsertValues(string $table, iterable $rows, array ++$i; } - $values[] = '(' . implode(', ', $placeholders) . ')'; + $values[] = implode(', ', $placeholders); } return $values; diff --git a/tests/Provider/QueryBuilderProvider.php b/tests/Provider/QueryBuilderProvider.php index 85df631c5..63b22d580 100644 --- a/tests/Provider/QueryBuilderProvider.php +++ b/tests/Provider/QueryBuilderProvider.php @@ -172,7 +172,7 @@ public static function batchInsert(): array 'customer', [], ['address'], - '', + 'expected' => '', ], 'customer3' => [ 'customer', @@ -242,7 +242,7 @@ public static function batchInsert(): array } })(), [], - '', + 'expected' => '', ], 'empty columns and non-exists table' => [ 'non_exists_table', diff --git a/tests/Support/DbHelper.php b/tests/Support/DbHelper.php index 8aeab5d9c..7f9be9733 100644 --- a/tests/Support/DbHelper.php +++ b/tests/Support/DbHelper.php @@ -21,7 +21,18 @@ final class DbHelper { public static function changeSqlForOracleBatchInsert(string &$str): void { - $str = str_replace('INSERT INTO', 'INSERT ALL INTO', $str) . ' SELECT 1 FROM SYS.DUAL'; + if (empty($str)) { + return; + } + + $str = str_replace( + ' VALUES (', + "\nSELECT ", + str_replace( + '), (', + " FROM DUAL UNION ALL\nSELECT ", + substr($str, 0, -1)) + ) . ' FROM DUAL'; } public static function getPsrCache(): CacheInterface From b1bbc17afd0d926ddfba7de4f89d8f33f2e37fea Mon Sep 17 00:00:00 2001 From: StyleCI Bot Date: Fri, 18 Oct 2024 07:00:29 +0000 Subject: [PATCH 2/3] Apply fixes from StyleCI --- tests/Support/DbHelper.php | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/tests/Support/DbHelper.php b/tests/Support/DbHelper.php index 7f9be9733..18970d50f 100644 --- a/tests/Support/DbHelper.php +++ b/tests/Support/DbHelper.php @@ -26,13 +26,14 @@ public static function changeSqlForOracleBatchInsert(string &$str): void } $str = str_replace( - ' VALUES (', - "\nSELECT ", - str_replace( - '), (', - " FROM DUAL UNION ALL\nSELECT ", - substr($str, 0, -1)) - ) . ' FROM DUAL'; + ' VALUES (', + "\nSELECT ", + str_replace( + '), (', + " FROM DUAL UNION ALL\nSELECT ", + substr($str, 0, -1) + ) + ) . ' FROM DUAL'; } public static function getPsrCache(): CacheInterface From 5486db2bc85f80d33365d37ec9371e485c4088f1 Mon Sep 17 00:00:00 2001 From: Tigrov Date: Fri, 18 Oct 2024 14:15:41 +0700 Subject: [PATCH 3/3] Add line to CHANGELOG.md [skip ci] --- CHANGELOG.md | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index cd645674b..5f7a5239d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -43,6 +43,7 @@ - New #882: Move `ArrayColumnSchema` and `StructuredColumnSchema` classes from `db-pgsql` package (@Tigrov) - New #883: Add `ColumnDefinitionBuilder` class and `QueryBuilderInterface::buildColumnDefinition()` method (@Tigrov) - Enh #885: Refactor `AbstractDsn` class (@Tigrov) +- Chg #889: Update `AbstractDMLQueryBuilder::insertBatch()` method (@Tigrov) ## 1.3.0 March 21, 2024