yiisoft / db

Yii Database Library
https://www.yiiframework.com/
BSD 3-Clause "New" or "Revised" License
134 stars 35 forks source link

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

Closed Tigrov closed 6 months ago

Tigrov commented 1 year ago

$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)

vjik commented 1 year ago

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 - 👍

Tigrov commented 1 year ago
  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

vjik commented 1 year ago

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?

Tigrov commented 1 year ago

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