Thanks for the tips Roger. I'll use them to debug this Thanks James
On Oct 4, 2011, at 11:23 PM, Roger Binns <rog...@rogerbinns.com> wrote: > -----BEGIN PGP SIGNED MESSAGE----- > Hash: SHA1 > > On 10/04/2011 10:52 PM, James Brison wrote: >> Can you open a database twice without closing it? > > That has absolutely nothing whatsoever with what you are seeing. > >> What is odd, is that I am using the prepare_v2 API. The documentation says >> it should not happen but I am getting a return code 17. > > The traditional reason you get this error is because of how prepared > statements are used internally. Effectively they say things like get the > value from column 7 of table 14. If you change the schema then those *may* > have moved around so prepare has to be run again. > > prepare_v2 causes sqlite3_step to have a do-while loop that reprepares the > statement if SQLITE_SCHEMA is returned. It tries this 5 times. In general > this will catch the database schema changing and automatically handle it. > > There is unfortunately a fly in the ointment and my biggest irritation with > SQLite. If the reprepare fails for (almost) any reason then SQLITE_SCHEMA > is returned instead of the actual failure code. For example if you call > prepare with a non-existent collation then SQLITE_ERROR is returned, but if > you removed the collation between the calls of prepare_v2 and step then you > get SQLITE_SCHEMA instead. > > The team decided this behaviour was a good thing to do: > > http://www.sqlite.org/src/tktview?name=8d510499cc > > You can find the actual error code by calling prepare again yourself when > getting SQLITE_SCHEMA. You can call sqlite3_sql() to get the original > statement text. You should also look at the error string being returned in > addition to the code. > > In my own code I gave up on prepare_v2 and use the older interface handling > SLITE_SCHEMA myself because of the API inconsistencies. It also saved a > redundant copy of the statement text since my cache has that as a key > anyway. (prepare_v2 causes a copy of the statement text to be saved to > reprepares can be done in step.) > > Roger > -----BEGIN PGP SIGNATURE----- > Version: GnuPG v1.4.11 (GNU/Linux) > > iEYEARECAAYFAk6L98gACgkQmOOfHg372QQTDgCg4iBLydcF1KtCRrpSIwsrK4jj > g+8AnjhVxZns9EXUJphYplUeZLxwDB8x > =GvAY > -----END PGP SIGNATURE----- > _______________________________________________ > 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