事务代码示例:
SQLiteDatabase db = dbOpenHelper.getWritableDatabase(); //开启事务
db.beginTransaction();
try {
db.execSQL("update person set amount=amount-10 where personid=?", new Object[]{1}); //设置事务标志为成功,当结束事务时就会提交事务
db.setTransactionSuccessful();
}
finally
{
//结束事务
db.endTransaction();
}