On 3 Jan 2017, at 2:28am, Domonic Tom <abdom...@hotmail.com> wrote: > Is there a way to test whether the DB_handle used when opening a database is > good? > > I need to find some way of testing it to make sure it represents the live > connection to a database?
It’s a little complicated. You should definitely check the result returned by sqlite3_open_v2() . But that call does not actually open the database file. SQLite actually does a sort-of lazy-open where the database file is actually opened only when needed. So to force SQLite to check that the file really is there (depending on your options) is writable (depending on your options) and has the right header for a SQLite database, you have to perform a write operation. Probably the least harmful command which causes SQLite to check for read/write permission would be to open the file as normal, set your timeout, then _exec something like CREATE TABLE IF NOT EXISTS DummyTable (a INT) (assuming you don’t use that tablename) and check the result code. Assuming you don’t terminate with an error at that point you would, of course, then issue DROP TABLE IF EXISTS DummyTable This code is safe even if two applications should be started up at the same time. Simon. _______________________________________________ sqlite-users mailing list sqlite-users@mailinglists.sqlite.org http://mailinglists.sqlite.org/cgi-bin/mailman/listinfo/sqlite-users