Comments (12)
Associative arrays tend not to be ordered; I know they are but when using them you don't want to depend on the order of associative elements...
from db.
And how this is different from arrays indexed by integers? You still can have [2 => 2, 1 => 1, 3 => 3]
.
from db.
from db.
Point 2 was solved but point 1 still actual
from db.
The problem is not associative array, but invalid order of elements. If you pass associative array with correct order, everything will work fine:
$x->batchInsert('table1', ['a', 'b'], ['a' => 345, 'b' => 123]);
Throwing exception will break perfectly fine working code.
from db.
It's not, both of those are dictionaries; however php doesn't have lists so they are also dictionaries... These are conceptually different. My point not related to the order of elements BTW, in the correct order things like typecasting still don't work. Check the source if you don't believe me...
from db.
I had similar issue and as simple solution I used keys from array as argument.
$array = ['b' => 123, 'a' => 345];
$x->batchInsert('table1', array_keys(reset($array)), $array);
This does not cover different keys order in every array but when every array has same keys order this should work. Also when you change/add/delete one of key this should still work.
from db.
Currently associative arrays have no meaning in batch insert. Keys are ignored. What's the use case for naming columns explicitly in each element of a huge data array?
from db.
I don't have one, I just happened to get the data with keys. Then I found out the hard way that typecasting was broken because of it.
from db.
Well, then we can conclude that the format supplied wasn't supported and it was said nowhere in the docs that it would work. I see no reason to support such format in the future.
from db.
@samdark You misunderstand me; I'm not proposing adding support, i'm proposing to make failure more obvious:
My proposal is to actively check each key in the row data and throw a hard exception if it's not numerical.
Since we're already iterating it's a cheap thing to do and will make non-apparent failures more obvious.
from db.
Ah, good to go then.
from db.
Related Issues (20)
- `Schema::hasTableName()` method is missing HOT 1
- Allow scalars `int|float|bool` in `Query::select()` HOT 1
- Changes before release 2.0.0
- Allow use `DMLQueryBuilderInterface::batchInsert()` without `$columns` HOT 4
- Add posibility to drop table `IF EXISTS` and `CASCADE`
- Allow pass `ExpressionInterface` as alias to `QueryPartsInterface::withQuery()` HOT 1
- No usage of `AbstractCommand::requireTransaction()` HOT 3
- Needs to refactor `getRawSql()`
- Bug in `Command::insertWithReturningPks()` with empty values
- `Command::upsertWithReturningPks()` required for `ActiveRecord::upsert()`
- update irc link
- Bug when try to `Command::update()` using `Expression`s in values or in where condition
- Add ability to create like condition as `%value`, `value%` and `value` without `%`
- Add new method `SchemaInterface::getUserDefinedTypes()`
- Add ability to create `SELECT` with `FOR UPDATE`
- Refactoring of `DbArrayHelper`
- Needs to refactor `Query::each()`
- Changes after release 2.0.0
- Fix `float` type in `AbstractCommand::getRawSql()`
- Changes before release 3.0.0
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from db.