GithubHelp home page GithubHelp logo

Comments (12)

SamMousa avatar SamMousa commented on May 28, 2024 1

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.

rob006 avatar rob006 commented on May 28, 2024 1

And how this is different from arrays indexed by integers? You still can have [2 => 2, 1 => 1, 3 => 3].

from db.

rob006 avatar rob006 commented on May 28, 2024 1

yiisoft/yii2#17066 (comment)

from db.

Tigrov avatar Tigrov commented on May 28, 2024 1

Point 2 was solved but point 1 still actual

from db.

rob006 avatar rob006 commented on May 28, 2024

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.

SamMousa avatar SamMousa commented on May 28, 2024

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.

paweljankowiak06 avatar paweljankowiak06 commented on May 28, 2024

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.

samdark avatar samdark commented on May 28, 2024

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.

SamMousa avatar SamMousa commented on May 28, 2024

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.

samdark avatar samdark commented on May 28, 2024

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.

SamMousa avatar SamMousa commented on May 28, 2024

@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.

samdark avatar samdark commented on May 28, 2024

Ah, good to go then.

from db.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.