vendredi 27 mars 2015

this code is not run on my mac, why sqlite do not open the database?


static sqlite3 *database;
static sqlite3_stmt *enableForeignKey;

@implementation DBAdapter

+ (sqlite3 *)sharedInstance {

if (database == NULL) {
sqlite3 *newDBconnection;

NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
NSString *documentsDirectory = [paths objectAtIndex:0];
NSString *path = [documentsDirectory stringByAppendingPathComponent:@"klb_db.sqlite"];

if (sqlite3_open([path UTF8String], &newDBconnection) == SQLITE_OK) {
//NSLog(@"Database Successfully Opened :)");
database = newDBconnection;

if (sqlite3_prepare_v2(database, "PRAGMA foreign_keys = ON", -1, &enableForeignKey, NULL) != SQLITE_OK) {
NSLog(@"ERROR IN PRAGMA!");
}

sqlite3_finalize(enableForeignKey);

} else {
NSLog(@"Error in opening database :(");
database = NULL;
}
}

return database;
}

Aucun commentaire:

Enregistrer un commentaire