Curious about this... it seems that even if I change the pathForResource to @"fadfdasfa" or other non-existent name, I still am logging "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");
The database is created for you if it does not already exist.
Open the database like this:
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
!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With