Within the code below, pathToNonDatabase is the road to an easy text file, not really a real sqlite database. I had been wishing for sqlite3_open to identify that, however it does not (db isn't NULL, and result is SQLITE_OK). So, how you can identify that the file isn't a valid sqlite database?

sqlite3 *db = NULL;
int result = sqlite3_open(pathToNonDatabase, &db);

if((NULL==db) || (result!=SQLITE_OK)) { 
   // invalid database
}

I believe a pragma integrity_check could get it done.