From 1e29cf4a0f16fd006e78e4ccaff190f3fcda5980 Mon Sep 17 00:00:00 2001 From: Kornel Date: Fri, 27 Jul 2018 17:13:11 +0100 Subject: [PATCH] Mark self.committed only after command succeeds Fixes #366 --- src/transaction.rs | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/transaction.rs b/src/transaction.rs index 3b4509a..89628e0 100644 --- a/src/transaction.rs +++ b/src/transaction.rs @@ -167,8 +167,9 @@ impl<'conn> Transaction<'conn> { } fn commit_(&mut self) -> Result<()> { + self.conn.execute_batch("COMMIT")?; self.committed = true; - self.conn.execute_batch("COMMIT") + Ok(()) } /// A convenience method which consumes and rolls back a transaction. @@ -177,8 +178,9 @@ impl<'conn> Transaction<'conn> { } fn rollback_(&mut self) -> Result<()> { + self.conn.execute_batch("ROLLBACK")?; self.committed = true; - self.conn.execute_batch("ROLLBACK") + Ok(()) } /// Consumes the transaction, committing or rolling back according to the current setting @@ -277,9 +279,10 @@ impl<'conn> Savepoint<'conn> { } fn commit_(&mut self) -> Result<()> { - self.committed = true; self.conn - .execute_batch(&format!("RELEASE {}", self.name)) + .execute_batch(&format!("RELEASE {}", self.name))?; + self.committed = true; + Ok(()) } /// A convenience method which rolls back a savepoint.