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 the settransactionsuccessful () method is not called, the transaction is rolled back. Example:
Sqlitedatabase DB = ....;
DB. begintransaction (); // start the transaction
Try {
Db.exe csql ("insert into person (name, age) values (?,?) ", New object [] {" Chuanzhi podcast ", 4 });
Db.exe csql ("Update person set name =? Where personid =? ", New object [] {" Chuanzhi ", 1 });
DB. settransactionsuccessful (); // call this method to submit the current transaction when it is executed to endtransaction (). If this method is not called, the transaction will be rolled back.
} Finally {
DB. endtransaction (); // The transaction identifier determines whether to commit or roll back the transaction.
}
DB. Close ();
The preceding two SQL statements are executed in the same transaction.