Sqlite3_open always returns SQLITE_OK?

Curious about this ... it seems that even if I change pathForResource to @ "fadfdasfa" or another non-existent name, will I still register "Database Opened"?

sqlite3 * myDatabase; NSString *path = [[NSBundle mainBundle] pathForResource:@"carsdatabase" ofType:@"db"]; if (sqlite3_open([path UTF8String], &myDatabase) == SQLITE_OK) NSLog(@"Database Opened"); else NSLog(@"Failed to Open"); 
+4
source share
3 answers

A database is created for you if it does not already exist.

+7
source

Open the database as follows:

 std::string filename("mydatabase.db"); sqlite3 *db; int rc = sqlite3_open_v2(filename.c_str(), &db, SQLITE_OPEN_READWRITE, NULL); 

Then it will return an error code (14) if the database file does not exist. However, if the file exists but is not a valid database, it returns SQLITE_OK !

+5
source

It looks like you are running the following in a terminal:

 sqlite3 test.db 

If it is not, it will be created for you. This way, you simply create a new database every time you change the name, and you will probably see it in your main package.

+1
source

All Articles