I am writing a linux database application in C(mysql) and somewhere in my code, I need to execute a number of insert statements. suppose (for any reason) some of the inserts failed during the process. Is there an easy way to roll back? or the only way is to keep the track of insert statements.

thank you

by the way, the simplified piece of code and supporting structs is as follows:

Dude - accept some answer you received - show some love to the people that are helping you
–
Tudor ConstantinJul 6 '11 at 5:42

I'm sorry but I'm not getting you! I did thank the people who answered me. and also gave some comments. did I do something wrong? or... was I supposed to do something else that I didn't? if it is so, please let me know coz I'm a new stackoverflow user.
–
rahmanJul 6 '11 at 7:17

were you talking about the vote down/vote up and accept? I just came to now about them :)
–
rahmanJul 6 '11 at 7:19

You're supposed to click the checkbox near an answer to "Accept" an answer as the right one. You should think carefully about which answer is the best before clicking the checkbox.
–
David GraysonJul 6 '11 at 15:50

thanks, I tried the following which didn't work(the program still does the insertion). what am i missing please:mysql_autocommit(conn,0); mysql_query(conn,"START TRANSACTION"); mysql_query(conn, "INSERT INTO writers VALUES('Honore')"); mysql_rollback(conn); mysql_close(conn);
–
rahmanJul 6 '11 at 6:47

update: as the mysql_rollback() manual says:"As of MySQL 5.0.3, the action of this function is subject to the value of the completion_type system variable." is this relevant in my case? where can I set it?
–
rahmanJul 6 '11 at 6:52

Unfortunately I haven't used MySQL transactions before and I don't immediately see anything wrong with your code, so I don't know. Maybe try doing mysql_query(conn, "ROLLBACK");? I think you should ask a new question with your new problem.
–
David GraysonJul 6 '11 at 15:49

thanks, I tried the following which didn't work(the program still does the insertion). what am i missing please:mysql_autocommit(conn,0); mysql_query(conn,"START TRANSACTION"); mysql_query(conn, "INSERT INTO writers VALUES('Honore')"); mysql_rollback(conn); // mysql_query(conn,"COMMIT"); mysql_close(conn);
–
rahmanJul 6 '11 at 6:36

update: as the mysql_rollback() manual says:"As of MySQL 5.0.3, the action of this function is subject to the value of the completion_type system variable." is this relevant in my case? where can I set it?
–
rahmanJul 6 '11 at 6:52