diff options
author | Joshua Hull <joshbuddy@gmail.com> | 2022-09-02 02:45:11 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-09-01 22:45:11 -0400 |
commit | 4ef63c9c0db77925ab91b95237f9e3802c4710a4 (patch) | |
tree | 68be44c04811559551b31a13f0c17e3bb6e5ebf0 /sqlite3.go | |
parent | Fix TestQueryer test to use exec for multistatement insertion (diff) | |
download | golite-4ef63c9c0db77925ab91b95237f9e3802c4710a4.tar.gz golite-4ef63c9c0db77925ab91b95237f9e3802c4710a4.tar.xz |
Rollback on constraint failure (#1071)
Always rollback on a commit error
Diffstat (limited to 'sqlite3.go')
-rw-r--r-- | sqlite3.go | 6 |
1 files changed, 4 insertions, 2 deletions
@@ -494,10 +494,12 @@ 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 { - // sqlite3 will leave the transaction open in this scenario. + if err != nil { + // sqlite3 may 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. + // We don't know if the ROLLBACK is strictly necessary, but according + // to sqlite's docs, there is no harm in calling ROLLBACK unnecessarily. tx.c.exec(context.Background(), "ROLLBACK", nil) } return err |