I am writing a simple C program to check if a File F is a usable SQLite3 database.
I tried writing gibberish into a file test.db, but sqlite3_open("test.db", &db) returned 0.
I suppose either sqlite3_status() or sqlite3_db_status() do what I want, but the documentation states something different.
Check out this thread.
It looks like sqlite3_open will return SQLITE_OK even if the file is not a database. However, when you try execute a statement you will get SQLITE_NOTADB. Instead of reading the header, you could just do something like SELECT * FROM sqlite_master; after opening the database and check if SQLITE_NOTADB is returned. You could go a step further and use the data returned to make sure all your tables exists.
the file must begin with a fixed header. if you want to recognise valid files, that should be fine.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With