> It is safe to read the first N bytes in a db file ... ? Yes. As far as I know, that's the only sure way to determine the version. Unfortunately, the form of the header changed in version 3, but if you read the first 33 bytes, you'll have an array that you can search for "SQLite 2" or "SQLite format 3". (You need to add a '\0' to terminate the string if you're using C string functions.)
Regards