On Mon, 2013-11-18 at 22:54 -0700, Keith Medcalf wrote: > >Since I run all of these statements withing transactions (between > >"BEGIN" statements and "COMMIT" / "ROLLBACK" statements"), my > >expectation is that SQLITE_BUSY will only ever be returned for > >the leading "BEGIN" statement. > > SQLITE_BUSY may be returned, for example, if the transaction is attempted to > be upgraded from a read transaction into a write transaction, and an update > lock cannot be obtained. > > "BEGIN" only begins a read transaction. "BEGIN IMMEDIATE" begins a > transaction and obtains update locks immediately. >
Thanks for the slightly more definitive answer than I could get on IRC. It doesn't exactly answer my question though. More precisely then, in the case that a read transaction is upgraded to a write transaction, either by issuing an INSERT/DELETE command or by issuing a nested BEGIN IMMEDIATE command, is it safe to retry sqlite3_exec() until SQLITE_BUSY is not returned anymore ? Or, must the entire transaction be retried from the beginning, in the case that SQLITE_BUSY is returned at the point of this upgrade from read to write transaction ? > What the documentation is saying however is a word to the wise: Always check > your return codes, and always deal with every situation that you can foresee. > If a situation arises for which you are not prepared then die -- as > expeditiously and as noisily as possible. Yes, good general advice of course. My particular interest here is to handle SQLITE_BUSY gracefully so that callers of my library don't have to deal with it. Similar to how one normally would check (errno == EINTR) in a read()/write() loop and keep writing until finished, or until an error from which one cannot recover, occurs (instead of propagating the cumbersome error up the call chain). You seem to suggest that I should fail loudly in the case of SQLITE_BUSY, this is exactly what I want to avoid. Cheers, -Tristan > > > > _______________________________________________ > sqlite-users mailing list > sqlite-users@sqlite.org > http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users _______________________________________________ sqlite-users mailing list sqlite-users@sqlite.org http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users