Skip to content

Commit 0acfafc

Browse files
authored
Properly handle automatic rollbacks in SQLite in Commit. (#36685)
1 parent ef513bd commit 0acfafc

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/Microsoft.Data.Sqlite.Core/SqliteTransaction.cs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,8 +83,11 @@ public override void Commit()
8383
throw new InvalidOperationException(Resources.TransactionCompleted);
8484
}
8585

86-
sqlite3_rollback_hook(_connection.Handle, null, null);
86+
// Do commit first and then clear the rollback hook.
87+
// Commit itself can fail (i.e. SQLITE_FULL) and then Dispose would throw
88+
// confusing "SQLite Error 1: 'cannot rollback - no transaction is active'" exception.
8789
_connection.ExecuteNonQuery("COMMIT;");
90+
sqlite3_rollback_hook(_connection.Handle, null, null);
8891
Complete();
8992
}
9093

0 commit comments

Comments
 (0)