Skip to content

Commit 15d5547

Browse files
committed
Always rollback on a commit error
1 parent b3cdbba commit 15d5547

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

sqlite3.go

+4-2
Original file line numberDiff line numberDiff line change
@@ -494,10 +494,12 @@ func (ai *aggInfo) Done(ctx *C.sqlite3_context) {
494494
// Commit transaction.
495495
func (tx *SQLiteTx) Commit() error {
496496
_, err := tx.c.exec(context.Background(), "COMMIT", nil)
497-
if err != nil && (err.(Error).Code == C.SQLITE_BUSY || err.(Error).Code == C.SQLITE_CONSTRAINT) {
498-
// sqlite3 will leave the transaction open in this scenario.
497+
if err != nil {
498+
// sqlite3 may leave the transaction open in this scenario.
499499
// However, database/sql considers the transaction complete once we
500500
// return from Commit() - we must clean up to honour its semantics.
501+
// We don't know if the ROLLBACK is strictly necessary, but according
502+
// to sqlite's docs, there is no harm in calling ROLLBACK unnecessarily.
501503
tx.c.exec(context.Background(), "ROLLBACK", nil)
502504
}
503505
return err

0 commit comments

Comments
 (0)