Skip to content Skip to sidebar Skip to footer

Sqlite3_open - Problems Checking If A File Is A Sqlite3 Database

I'm working with sqlite3 for the first time, and cannot get it to properly check a file before it opens it. So far, sqlite always returns OK on any file. Also, the file name is a v

Solution 1:

sqlite3_open doesn't actually read the file until the first non-pragma statement is prepared.

sqlite3_open_v2 provides other options.

Solution 2:

Does your code compile? I believe this is an error

if (SQLITE_OK == rc = sqlite3_open(filename,&db)) { /* ... */ }

it's the same as

if ((SQLITE_OK == rc) = sqlite3_open(filename,&db)) { /* ... */ }

and you cannot assign something (the result of the sqlite3_open() call) to (SQLITE_OK == rc).

Try this:

if ((rc = sqlite3_open(filename,&db)) == SQLITE_OK) { /* ... */ }
/* or, if you really want the constant on the left side of the comparison */if (SQLITE_OK == (rc = sqlite3_open(filename,&db))) { /* ... */ }

Post a Comment for "Sqlite3_open - Problems Checking If A File Is A Sqlite3 Database"