mardi 3 novembre 2015

Sqlite Error - "Insertion Failure: unable to open database file"

I'm using NSTimer to call the below function every second and and pass the values for activityType and activityConfidence using parameters. After some successful insertions I'm getting an error "unable to open database file"

-(void)tableInsertionFunction:(NSString *)activityType confidenceIs:(NSString *)activityConfidence {

dirPaths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory, NSUserDomainMask, YES);
docsDir = dirPaths[0];
databasePath =  [docsDir stringByAppendingPathComponent:@"mainSDK.db"];
dbpath = [databasePath UTF8String];

if (sqlite3_open(dbpath, & demoDB) == SQLITE_OK) {

    NSString *insertStatement = [NSString stringWithFormat: @"INSERT INTO activityTable ( activityType , activityConfidence) VALUES ('%@' , '%@' )",activityType, activityConfidence];

    sqlite3_stmt *statement;
    const char *insert_stmt = [insertStatement UTF8String];
    sqlite3_prepare_v2(demoDB, insert_stmt,-1, &statement, NULL);
    if (sqlite3_step(statement) == SQLITE_DONE) {
        NSLog(@"Insertion Successful");
    }
    else {
        NSLog(@"Insertion Failure: %s",sqlite3_errmsg(demoDB));
    }

    sqlite3_close(demoDB);
}

}

Aucun commentaire:

Enregistrer un commentaire