Sqlite错误 - “插入失败:无法打开数据库文件”

时间:2015-11-03 10:54:12

标签: ios objective-c sqlite

我正在使用NSTimer每秒调用以下函数,并使用参数传递activityType和activityConfidence的值。在一些成功插入后,我收到错误“无法打开数据库文件”

-(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);
    }
}

0 个答案:

没有答案