+ 2
MySQL hard question
It's there a way to rollback automatically if a query fails?? The values in my query can change What I'm trying to say is that my query is being modified by placeholder %s I want to rollback if any of the queries fails... I've been looking for a while and haven't found a solution... š¢
4 Answers
+ 2
This should help:
How to use START TRANSACTION, COMMIT, and ROLLBACK in MySQL
https://dev.mysql.com/doc/refman/5.7/en/commit.html
+ 1
Try using:
SET autocommit=0;
Then your query, and if it fails, then use:
ROLLBACK;
But I think you should test it first by inserting a "test row" and then delete it again.
+ 1
Iām not an expert about mysql but what about bulk operations?
I understand that you are trying to do some inserts.
Use a single transaction to englobe all these operations. If any of the operations fails then the transaction fails
0
Update I just found that there are no autorollbacks in mysql so I have to code that behavior now I'm looking for a solution that's checks if one query works to run another and if the second fails revert the changes