Take the 2-minute tour ×

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

share|improve this question
add comment

1 Answer

up vote 0 down vote accepted

If execDML throws an exception when an error occurs, you can use an exception handler:

try {
    db.execDML("insert ...");
    db.execDML("insert ...");
} catch (...) {

If it didn't, you would have to write a wrapper function for execDML that checks the return code and does throw. However, it appears CppSQLite already does this for you.

share|improve this answer
add comment

Your Answer


