Sqlite3 transaction (transaction) Action in cocos2d-x

Source: Internet
Author: User

 

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

 

 

 

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.