On 10/08/2013 07:39 PM, Clemens Ladisch wrote:
Paul Harris wrote:
Many years ago, Igor mentioned that you should always reset/finalize any
prepared statements before calling COMMIT.

I am wondering, is this still true?
Yes.

Do I have to reset before I commit?  And where is the requirement written
in the sqlite documentation?
<http://www.sqlite.org/lang_transaction.html> says:
| An implicit transaction (a transaction that is started automatically,
| not a transaction started by BEGIN) is committed automatically when
| the last active statement finishes. A statement finishes when its
| prepared statement is reset or finalized.
|
| The explicit COMMIT command runs immediately, even if there are
| pending SELECT statements. However, if there are pending write
| operations, the COMMIT command will fail with an error code
| SQLITE_BUSY.

Actually, I think the paragraphs above mean that it is
Ok to COMMIT while you have active read-only statements
(e.g. SELECT statements). The COMMIT statement will
commit the write-transaction to disk, but a read-transaction
will be held open until all the SELECTs have finished.

As for "pending write operations", I think you only get
this if you try to COMMIT in the callback for a user-defined
function or some such shenanigans. Calling sqlite3_step()
on a write statement but not calling reset()/finalize()
shouldn't leave it pending - a write statement is no longer
pending once it has returned SQLITE_DONE.




_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to