From 6b59a483eb3f8bf8be6c754a725cbb37b66881c9 Mon Sep 17 00:00:00 2001 From: Joshua Hull Date: Fri, 5 Aug 2022 15:34:02 +0200 Subject: [PATCH] Rollback on constraint failure --- sqlite3.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/sqlite3.go b/sqlite3.go index e037857d..6e67e7cc 100644 --- a/sqlite3.go +++ b/sqlite3.go @@ -494,7 +494,7 @@ func (ai *aggInfo) Done(ctx *C.sqlite3_context) { // Commit transaction. func (tx *SQLiteTx) Commit() error { _, err := tx.c.exec(context.Background(), "COMMIT", nil) - if err != nil && err.(Error).Code == C.SQLITE_BUSY { + if err != nil && (err.(Error).Code == C.SQLITE_BUSY || err.(Error).Code == C.SQLITE_CONSTRAINT) { // sqlite3 will leave the transaction open in this scenario. // However, database/sql considers the transaction complete once we // return from Commit() - we must clean up to honour its semantics.