In sqlite3, transactions do not extract an interface. I had to write it into SQL statements, but it was not too troublesome.
sqlite3_exec ( m_pDB , "begin transaction" , 0 , 0 , & errMsg );sqlite3_exec ( m_pDB , "commit transaction" , 0 , 0 , & errMsg );sqlite3_exec ( m_pDB , "rollback transaction" , 0 , 0 , &errMsg );
I encapsulate transaction operations into two functions and call them at the beginning and end. If the transaction is not completed when the database is closed,
By default
Rollback.
The function is defined and implemented as follows:
/** To start a transaction, the call should end after the transaction is completed. ** Return sqlite_xxx standard macro */INT begintransaction ();/** to end a transaction. * The parameter is the return value of the previously executed SQL statement, that is, whether the result is successful or rolled back. ** Return sqlite_xxx standard macro */INT endtransaction (INT sqlresult );
Int datautil: begintransaction () {char MSG [err_length] = {0}; char * errmsg = MSG; int result = sqlite3_exec (m_pdb, "begin transaction", 0, 0, & errmsg); If (result! = Sqlite_ OK) cclog ("failed to start transaction record, error code: % d, error cause: % s \ n", result, errmsg); return result;} int datautil :: endtransaction (INT sqlresult) {If (sqlresult = sqlite_ OK) {char MSG [err_length] = {0}; char * errmsg = MSG; int result = sqlite3_exec (m_pdb, "Commit transaction", 0, 0, & errmsg); If (result! = Sqlite_ OK) cclog ("failed to commit transaction records, error code: % d, error cause: % s \ n", result, errmsg); return result ;} else {char MSG [err_length] = {0}; char * errmsg = MSG; int result = sqlite3_exec (m_pdb, "rollback transaction", 0, 0, & errmsg ); if (result! = Sqlite_ OK) cclog ("rolling back transaction records failed, error code: % d, error cause: % s \ n", result, errmsg); return result ;}}
This blog from a shura Road, reproduced please note the Source: http://blog.csdn.net/fansongy/article/details/8966730