Skip to content

Commit

Permalink
Update after merge
Browse files Browse the repository at this point in the history
  • Loading branch information
Tigrov committed Nov 4, 2023
1 parent 1318a7e commit 5ee6fb6
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 51 deletions.
38 changes: 3 additions & 35 deletions src/QueryBuilder/AbstractDMLQueryBuilder.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand Down Expand Up @@ -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;
Expand All @@ -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 */
Expand Down
16 changes: 0 additions & 16 deletions tests/Provider/CommandProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -424,22 +424,6 @@ public static function batchInsert(): array
':qp3' => 2.0,
],
],
'with empty columns' => [
'customer',
[],
'values' => [['10.0', '[email protected]']],
'expected' => DbHelper::replaceQuotes(
<<<SQL
INSERT INTO [[customer]] (`id`, `email`) VALUES (:qp0, :qp1)
SQL,
static::$driverName,
),
'expectedParams' => [
':qp0' => 10,
':qp1' => '[email protected]',
],
4,
],
];
}

Expand Down

0 comments on commit 5ee6fb6

Please sign in to comment.