Skip to content

Commit

Permalink
fix sqlite chan closed bug
Browse files Browse the repository at this point in the history
  • Loading branch information
zhuxiujia committed Feb 2, 2022
1 parent fc9e803 commit 75ac35c
Showing 1 changed file with 9 additions and 2 deletions.
11 changes: 9 additions & 2 deletions example/src/transaction/tx.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())
Expand Down

0 comments on commit 75ac35c

Please sign in to comment.