zombiezen / go-sqlite

Low-level Go interface to SQLite 3
https://pkg.go.dev/zombiezen.com/go/sqlite
ISC License
699 stars 16 forks source link

Transaction helpers don't work when manual BEGIN/END do #33

Closed anacrolix closed 2 years ago

anacrolix commented 2 years ago

Using sqlitex.Transaction I get a lot of:

sqlite: step: database is locked: cannot commit transaction - SQL statements in progress

But if I manually sqlitex.Exec(... "BEGIN") and "END", I don't have this problem. Is there a difference I should be aware of?

anacrolix commented 2 years ago

This might be a subtle error in my own calling code. I get the same issue with crawshaw.

zombiezen commented 2 years ago

Seems that the error message indicates a statement that has not been stepped through fully: https://sqlite.org/forum/info/52f001ddd522c2bd

Can you post a minimal, reproducible example?

anacrolix commented 2 years ago

I think it has to do with unclosed incremental BLOB handles, which may be undocumented?

zombiezen commented 2 years ago

That's quite possible: blob handles are guaranteed to be a snapshot of their value during the transaction.

anacrolix commented 2 years ago

It looks like stmt_finalize is called from sqlite3_blob_close and that decrements a write counter that prevents savepoints. I don't think this is an issue in this implementation but a general sqlite issue. Thanks Ross