Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

sqlite3_open - Can't open database?

Tags:

sqlite

iphone

I have the following statement in my code:

if(sqlite3_open([databasePath UTF8String], &database) == SQLITE_OK) 

but it doesn't seem to be opening my database.

Any ideas ?

like image 583
Stephen Avatar asked Mar 06 '26 01:03

Stephen


1 Answers

Without knowing anything else about your problem, one can only assume that your path is invalid.

Try using this path to see if it works

NSArray* paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString* documentsDirectory = [paths lastObject];
NSString* databasePath = [documentsDirectory stringByAppendingPathComponent:@"mydb.sqlite"];

if(sqlite3_open([databasePath UTF8String], &database) == SQLITE_OK) {
     NSLog(@"Opened sqlite database at %@", databasePath);
    //...stuff
} else {
     NSLog(@"Failed to open database at %@ with error %s", databasePath, sqlite3_errmsg(database));
     sqlite3_close (database);
}
like image 79
Akusete Avatar answered Mar 08 '26 13:03

Akusete



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!