diff --git a/src/transaction.rs b/src/transaction.rs index 5cf26a4..a7abaf5 100644 --- a/src/transaction.rs +++ b/src/transaction.rs @@ -91,7 +91,6 @@ pub struct Transaction<'conn> { pub struct Savepoint<'conn> { conn: &'conn Connection, name: String, - depth: u32, drop_behavior: DropBehavior, committed: bool, } @@ -158,13 +157,13 @@ impl Transaction<'_> { /// ``` #[inline] pub fn savepoint(&mut self) -> Result> { - Savepoint::with_depth(self.conn, 1) + Savepoint::new_(self.conn) } /// Create a new savepoint with a custom savepoint name. See `savepoint()`. #[inline] pub fn savepoint_with_name>(&mut self, name: T) -> Result> { - Savepoint::with_depth_and_name(self.conn, 1, name) + Savepoint::with_name_(self.conn, name) } /// Get the current setting for what happens to the transaction when it is @@ -249,50 +248,44 @@ impl Drop for Transaction<'_> { impl Savepoint<'_> { #[inline] - fn with_depth_and_name>( - conn: &Connection, - depth: u32, - name: T, - ) -> Result> { + fn with_name_>(conn: &Connection, name: T) -> Result> { let name = name.into(); conn.execute_batch(&format!("SAVEPOINT {name}")) .map(|_| Savepoint { conn, name, - depth, drop_behavior: DropBehavior::Rollback, committed: false, }) } #[inline] - fn with_depth(conn: &Connection, depth: u32) -> Result> { - let name = format!("_rusqlite_sp_{depth}"); - Savepoint::with_depth_and_name(conn, depth, name) + fn new_(conn: &Connection) -> Result> { + Savepoint::with_name_(conn, "_rusqlite_sp") } /// Begin a new savepoint. Can be nested. #[inline] pub fn new(conn: &mut Connection) -> Result> { - Savepoint::with_depth(conn, 0) + Savepoint::new_(conn) } /// Begin a new savepoint with a user-provided savepoint name. #[inline] pub fn with_name>(conn: &mut Connection, name: T) -> Result> { - Savepoint::with_depth_and_name(conn, 0, name) + Savepoint::with_name_(conn, name) } /// Begin a nested savepoint. #[inline] pub fn savepoint(&mut self) -> Result> { - Savepoint::with_depth(self.conn, self.depth + 1) + Savepoint::new_(self.conn) } /// Begin a nested savepoint with a user-provided savepoint name. #[inline] pub fn savepoint_with_name>(&mut self, name: T) -> Result> { - Savepoint::with_depth_and_name(self.conn, self.depth + 1, name) + Savepoint::with_name_(self.conn, name) } /// Get the current setting for what happens to the savepoint when it is @@ -352,7 +345,7 @@ impl Savepoint<'_> { } match self.drop_behavior() { DropBehavior::Commit => self.commit_().or_else(|_| self.rollback()), - DropBehavior::Rollback => self.rollback(), + DropBehavior::Rollback => self.rollback().and_then(|_| self.commit_()), DropBehavior::Ignore => Ok(()), DropBehavior::Panic => panic!("Savepoint dropped unexpectedly."), }