diff --git a/src/QueryBuilder/AbstractDMLQueryBuilder.php b/src/QueryBuilder/AbstractDMLQueryBuilder.php index 13ce224c0..b29d08efd 100644 --- a/src/QueryBuilder/AbstractDMLQueryBuilder.php +++ b/src/QueryBuilder/AbstractDMLQueryBuilder.php @@ -21,21 +21,16 @@ use function array_diff; use function array_fill_keys; use function array_filter; -use function array_key_first; use function array_keys; use function array_map; use function array_merge; -use function array_slice; use function array_unique; use function array_values; -use function count; use function implode; use function in_array; -use function is_array; use function is_string; use function json_encode; use function preg_match; -use function reset; use function sort; /** @@ -63,32 +58,9 @@ public function batchInsert(string $table, array $columns, iterable $rows, array $values = []; $columns = $this->getNormalizeColumnNames('', $columns); - $columnSchemas = $this->schema->getTableSchema($table)?->getColumns() ?? []; - $values = []; - $columns = $this->getNormalizeColumnNames($columns); - $columnSchemas = $this->schema->getTableSchema($table)?->getColumns() ?? []; - - if ($columns === []) { - $columnNames = []; - if (is_array($rows)) { - /** @psalm-var iterable $row */ - $row = reset($rows); - - if (is_array($row)) { - if (is_string(array_key_first($row))) { - $columnNames = array_keys($row); - } else { - $columnNames = array_slice(array_keys($columnSchemas), 0, count($row)); - } - - $columns = array_combine($columnNames, $columnNames); - } - } - } else { - $columnNames = array_values($columns); - } - + $columnNames = array_values($columns); $columnKeys = array_fill_keys($columnNames, false); + $columnSchemas = $this->schema->getTableSchema($table)?->getColumns() ?? []; foreach ($rows as $row) { $i = 0; @@ -99,11 +71,7 @@ public function batchInsert(string $table, array $columns, iterable $rows, array */ foreach ($row as $key => $value) { /** @psalm-var string|int $columnName */ - $columnName = $columns[$key] ?? ( - isset($columnKeys[$key]) - ? $key - : $columnNames[$i] ?? $i - ); + $columnName = $columns[$key] ?? (isset($columnKeys[$key]) ? $key : $columnNames[$i] ?? $i); if (isset($columnSchemas[$columnName])) { /** @psalm-var mixed $value */ diff --git a/tests/Provider/CommandProvider.php b/tests/Provider/CommandProvider.php index 387fc353d..9f7408b73 100644 --- a/tests/Provider/CommandProvider.php +++ b/tests/Provider/CommandProvider.php @@ -424,22 +424,6 @@ public static function batchInsert(): array ':qp3' => 2.0, ], ], - 'with empty columns' => [ - 'customer', - [], - 'values' => [['10.0', 'info@gmail.com']], - 'expected' => DbHelper::replaceQuotes( - << [ - ':qp0' => 10, - ':qp1' => 'info@gmail.com', - ], - 4, - ], ]; }