aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authormattn <mattn.jp@gmail.com>2016-07-15 22:38:49 +0900
committerGitHub <noreply@github.com>2016-07-15 22:38:49 +0900
commite118d4451349065b8e7ce0f0af32e033995363f8 (patch)
tree1a745770bd8bbf2f5b0346e3a2160e496c8551ad
parentMerge pull request #304 from steffengy/master (diff)
parentFix inconsistent tx state with database/sql. (diff)
downloadgolite-e118d4451349065b8e7ce0f0af32e033995363f8.tar.gz
golite-e118d4451349065b8e7ce0f0af32e033995363f8.tar.xz
Merge pull request #300 from sqweek/issue184
Fix inconsistent tx state with database/sql.
-rw-r--r--sqlite3.go6
1 files changed, 6 insertions, 0 deletions
diff --git a/sqlite3.go b/sqlite3.go
index 852c299..f3c1226 100644
--- a/sqlite3.go
+++ b/sqlite3.go
@@ -296,6 +296,12 @@ func (ai *aggInfo) Done(ctx *C.sqlite3_context) {
// Commit transaction.
func (tx *SQLiteTx) Commit() error {
_, err := tx.c.exec("COMMIT")
+ if err != nil && err.(Error).Code == C.SQLITE_BUSY {
+ // 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.
+ tx.c.exec("ROLLBACK")
+ }
return err
}