In the code below, pathToNonDatabase
is the path to a simple text file, not a real sqlite database. I was hoping for sqlite3_open
to detect that, but
sqlite opens databases lazily. Just do something immediately after opening that requires it to be a database.
The best is probably pragma schema_version;
.
CREATE TABLE
, etc)If you want a somewhat more thorough check, you can use pragma quick_check;
. This is a lighter-weight integrity check, which skips checking that the contents of the tables line up with the indexes. It can still be very slow.
Avoid integrity_check
. It not only checks every page, but then verifies the contents of the tables against the indexes. This is positively glacial on a large database.