Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/conn/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1205,7 +1205,7 @@ impl Conn {
}

/// Requires that `self.inner.tx_status != TxStatus::None`
async fn rollback_transaction(&mut self) -> Result<()> {
pub(crate) async fn rollback_transaction(&mut self) -> Result<()> {
debug_assert_ne!(self.inner.tx_status, TxStatus::None);
self.inner.tx_status = TxStatus::None;
self.query_drop("ROLLBACK").await
Expand Down
3 changes: 1 addition & 2 deletions src/queryable/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,7 @@ impl Conn {
pub(crate) async fn clean_dirty(&mut self) -> Result<()> {
self.drop_result().await?;
if self.get_tx_status() == TxStatus::RequiresRollback {
self.set_tx_status(TxStatus::None);
self.exec_drop("ROLLBACK", ()).await?;
self.rollback_transaction().await?;
}
Ok(())
}
Expand Down
10 changes: 4 additions & 6 deletions src/queryable/transaction.rs
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,8 @@ impl<'a> Transaction<'a> {

let mut conn = conn.into();

conn.clean_dirty().await?;

if conn.get_tx_status() != TxStatus::None {
return Err(DriverError::NestedTransaction.into());
}
Expand Down Expand Up @@ -188,19 +190,15 @@ impl<'a> Transaction<'a> {
match self.try_commit().await {
Ok(..) => Ok(()),
Err(e) => {
self.0.query_drop("ROLLBACK").await.unwrap_or(());
self.0.set_tx_status(TxStatus::None);
self.0.rollback_transaction().await.unwrap_or(());
Err(e)
}
}
}

/// Performs `ROLLBACK` query.
pub async fn rollback(mut self) -> Result<()> {
let result = self.0.query_iter("ROLLBACK").await?;
result.drop_result().await?;
self.0.set_tx_status(TxStatus::None);
Ok(())
self.0.rollback_transaction().await
}
}

Expand Down