I get “unable to open database file” when executing rc = sqlite3_open(“test.db”, &db); ??
sqlite3 *db; // sqlite3 db struct
char *zErrMsg = 0;
int rc;
// Open the test.db file
rc = sqlite3_open("test.db", &db); // <-- creates DB if not found ??
if( rc ){
// failed
fprintf(stderr, "ERROR: Can't open database: %s\n", sqlite3_errmsg(db));
}
sqlite3_openreturns an error if the database does not already exist. To create the database if it doesn’t already exist, usesqlite3_open_v2with theSQLITE_OPEN_CREATEandSQLITE_OPEN_READWRITEflags (both are required):Reference
To find
/* DB PATH */, you need to base the filename off of the documents directory:You can use this convenience method to combine the documents path with the database name: