db icon indicating copy to clipboard operation
db copied to clipboard

Allow use `DMLQueryBuilderInterface::batchInsert()` without `$columns`

Open Tigrov opened this issue 7 months ago • 4 comments

$columns can be obtained

  1. from $rows if values are associative array
  2. from $table if table shema found
  3. or generate insert without columns if no columns found

Need to replace arguments from DMLQueryBuilderInterface::batchInsert(string $table, array $columns, iterable $rows, array &$params = []) to DMLQueryBuilderInterface::batchInsert(string $table, iterable $rows, array $columns = [], array &$params = [])

This will allow to use the method this way batchInsert($table, $rows)

Tigrov avatar Nov 10 '23 05:11 Tigrov

1 - 👍 2 - but we don't know order of fields in rows, also rows may contain not all fields. Seems, it's can lead to errors in user code. 3 - 👍

vjik avatar Nov 10 '23 06:11 vjik

  1. This is almost the same case as case 3, but we can get fields from table schema for casting type of values

If no colums passed then means columns have order as in table schema

INSERT INTO table ~~(columns)~~ VALUES (values)

not all fields also possible, only first fields will be used

Tigrov avatar Nov 10 '23 08:11 Tigrov

If no colums passed then means columns have order as in table schema

But why need columns in this case? Isn't that the equivalent to way 3?

vjik avatar Nov 10 '23 13:11 vjik

But why need columns in this case? Isn't that the equivalent to way 3?

Columns are needed for type casting and seems not all DBMS supports partial lists of values, but we can support them

Tigrov avatar Nov 10 '23 14:11 Tigrov