diff --git a/example/src/transaction/tx.rs b/example/src/transaction/tx.rs index 49e7f93..e4f1819 100644 --- a/example/src/transaction/tx.rs +++ b/example/src/transaction/tx.rs @@ -8,13 +8,20 @@ use cdbc_sqlite::SqlitePool; fn main() -> cdbc::Result<()> { let pool = make_sqlite()?; let mut tx = RefCell::new(pool.begin()?); - // Defer was able to guarantee that even the following code panic would commit + defer!(||{ + // Defer was able to guarantee that even the following code panic would commit if !tx.borrow().is_done(){ tx.borrow_mut().commit(); - println!("tx committed"); + println!("----------tx committed-----------"); } }); + + // //change this to true,also the tx will be committed + // if true{ + // panic!("oh it is panic!"); + // } + let r = tx.borrow_mut().execute("update biz_activity set name = '2'")?; println!("rows_affected: {}", r.rows_affected()); Ok(())