Giter VIP home page Giter VIP logo

Comments (7)

acoulton avatar acoulton commented on July 24, 2024 1

SQL doesn't support multiple UPDATES in a single query, if you want to update N rows (with different values for each row) you'll need to execute multiple queries.

from database.

enov avatar enov commented on July 24, 2024

@nixprosoft Your question is not clear to me. I did not understand what you're asking for.

The code below is doesn't pay attention to begin/commit commands and executing N queries

Your code is well doing a safe transaction with the default instance of the database.

Regarding your update query, we can not give an answer to that, as it is specific to your application.

Kindly note that Kohana Github repo is not the place to seek support. You might want to head to discourse.kohanaframework.org and ask your questions there.

Thanks!

from database.

nixprosoft avatar nixprosoft commented on July 24, 2024

Thanks. I'm not searching support. I'm telling you - there is a bug. For example, if I comment out line:
//Database::instance()->commit();
the query will execute instead. How do you explain that?

from database.

nixprosoft avatar nixprosoft commented on July 24, 2024

When I need to update N rows by transaction, I'm expecting 1 query to execute, not N. Am I correct?

from database.

acoulton avatar acoulton commented on July 24, 2024

Transactions don't affect the number of queries that execute. They just wrap a set of queries together, so you can ask the DB to cancel (rollback) or save (commit) them as a batch.

If you call $query->execute() N times, with or without a transaction, then N queries will execute.

from database.

enov avatar enov commented on July 24, 2024

As @acoulton has well stated, your queries are executed. Whether they are committed or not, that is a different story.

When you omit the explicit commit, the queries get rolled back at the end, when PHP closes the database connection. Except when you have persistent database connections, your queries will get committed because of subsequent START TRANSACTION calls, at the beginning of your script.

You probably know that returning count($items) does not return any actual execution info from the database. Your Database class might be fake, not doing real database stuff, and you can still have count($items) returned.

I have added some references. Allow me to politely close the issue. Reopen if you still think there is bug.

http://dev.mysql.com/doc/refman/5.7/en/commit.html
http://dev.mysql.com/doc/refman/5.7/en/implicit-commit.html

Cheers!

from database.

nixprosoft avatar nixprosoft commented on July 24, 2024

My bad. Thanks for explanations.
Now I'm searching best practice to execute batch of queries (like INSERT N rows into one table with only one query) with QueryBuilder. Can you give me a link?
P.S. Sorry for off topic.

from database.

Related Issues (11)

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.