Giter VIP home page Giter VIP logo

Comments (3)

yadakhov avatar yadakhov commented on September 3, 2024

Sure. Do a PR and I'll merge.

Note that affected rows counts as 2 for duplicates.

http://stackoverflow.com/questions/3747314/why-are-2-rows-affected-in-my-insert-on-duplicate-key-update

from insert-on-duplicate-key.

stebogit avatar stebogit commented on September 3, 2024

@votemike I'm not sure how to use this feature when inserting multiple rows at once, and I believe there is at least an imprecision in the docs.
The current documentation says:

/*
* @return int 0 if row is not changed, 1 if row is inserted, 2 if row is updated
*/
public static function insertOnDuplicateKey(array $data, array $updateColumns = null)

however with multiple inserts/updates the output is the sum of the single affected-rows values.
Now I get that for a single operation 0-1-2 values help to discriminate what happened, but here, from the sum, how do I define how many rows have been inserted and how many updated?

It would be nice to return an array like

[ 'updates' => 2, 'inserts' => 17 ]

but is it even possible, I mean does MySQL even allow to discriminate between insert/update in a big single statement like the one the method creates?

Thanks, and thank you @yadakhov for the great tool! 👍

from insert-on-duplicate-key.

votemike avatar votemike commented on September 3, 2024

Wow, it's been a while since I did this work. @vifer do you still work with this? Any idea about @stebogit 's question?

from insert-on-duplicate-key.

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.