I am using open source CppSQLite wrapper in my project to access the SQLIte3 Table,
I am trying to insert couple of sql queries to the sqlite3 table. If any of the insert query failed, I need to roll back the transaction.
My code similar to the following:
CppSQLiteDB db;
db.execDML(L"begin transaction;");
db.execDML("insert into emp values (7, 'Test7');");
db.execDML("insert into emp values (8, 'Test8');");
db.execDML("insert into emp values (9, 'Test9');");
db.execDML(L"commit transaction;");
How can I rollback the transaction if any one of the insert query failed. Should I check the return code of each insert query?
Reference:
http://www.codeproject.com/Articles/6343/CppSQLite-C-Wrapper-for-SQLite
If
execDMLthrows an exception when an error occurs, you can use an exception handler:If it didn’t, you would have to write a wrapper function for
execDMLthat checks the return code and does throw. However, it appears CppSQLite already does this for you.