From b2987ccc32872924355ccc1802963d51a28ad7fe Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Benjamin=20Schr=C3=B6ter?= Date: Wed, 11 Nov 2015 13:14:04 +0100 Subject: [PATCH] When an exception is thrown during commit() it will execute a rollback cmd on the database. --- src/SQLite.Net/SQLiteConnection.cs | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/src/SQLite.Net/SQLiteConnection.cs b/src/SQLite.Net/SQLiteConnection.cs index 475a9aa8..f0716793 100644 --- a/src/SQLite.Net/SQLiteConnection.cs +++ b/src/SQLite.Net/SQLiteConnection.cs @@ -1135,9 +1135,29 @@ public void Commit() { if (Interlocked.Exchange(ref _transactionDepth, 0) != 0) { - Execute("commit"); + // Do nothing on a commit with no open transaction + + try + { + Execute("commit"); + } + catch (Exception) + { + // something went wrong. at least we should clean up + try + { + Execute("rollback"); + } + catch + { + // if rollback won't work (e.g. commit was already ok) just silent fail + // i did not see this, but just to be safe + } + + // and throw the original exception anyway + throw; + } } - // Do nothing on a commit with no open transaction } ///