Use the begintransaction () method of sqlitedatabase to start a transaction. When the program runs to the endtransaction () method, it checks whether the transaction flag is successful. If the program runs to the endtransaction () method () previously, the settransactionsuccessful () method was called to set the transaction flag to successful, then the transaction is committed. If settransactionsuccessful () is not called ()
Method to roll back the transaction. Transaction Processing Applications: in many cases, when we need to insert a large amount of data into SQLite in batches, the use of the add method alone leads to slow application response, because when SQLite inserts data, a default statement is a transaction, and disk operations are performed as many data records as possible. For example, the initial 8000 records mean 8000 read/write operations on the disk. It also aims to ensure data consistency and avoid data loss.
Sqlitedatabase DB = dbopenhelper. getwritabledatabase ();
// Enable transaction dB. begintransaction (); try {// batch processing operation
// Do something db.exe csql ("SQL statement", new object [] {}); db.exe csql ("SQL statement", new object [] {}); // set the transaction flag to successful. When the transaction ends, the transaction dB is committed. settransactionsuccessful ();} catch (exception e ){
}
Finally {// end transaction dB. endtransaction ();}