适用于模拟器6.1,但不适用于iPhone iOS 6.1

时间:2013-03-04 11:19:42

标签: iphone

我正在使用iPhone 6.1模拟器,它的工作原理。但是,当我去我的iPhone [iOS 6.1]时,我收到错误“更新时出错。不是错误”。帮助!

    NSString *filePath = [[[NSBundle mainBundle] resourcePath ]stringByAppendingPathComponent:@"myDatabase.sqlite"];


    NSString* str2 = SeqNo1.text;
    sqlite3 *database;
    sqlite3_stmt *updateStmt=NULL;
    if(sqlite3_open([filePath UTF8String], &database) == SQLITE_OK)
    {
        NSString* sql= [NSString stringWithFormat:@"UPDATE MyTable Set MyField2 = \"%@\" WHERE MyField1 = \"%@\"", @"Y", str2];
        if(sqlite3_prepare(db, [sql cStringUsingEncoding:NSASCIIStringEncoding], -1, &updateStmt, NULL) != SQLITE_OK)
            NSLog(@"Error while creating update statement. %s", sqlite3_errmsg(database));
    }
    if(sqlite3_open([filePath UTF8String], &database) == SQLITE_OK)        
    {
    int step = sqlite3_step(updateStmt);
    if(step != SQLITE_DONE)

        NSLog(@"Error while updating. %s", sqlite3_errmsg(database));  // THIS WHERE THE ERROR IS OCCURRING
    sqlite3_finalize(updateStmt);
    sqlite3_close(database);
    }
    else{
        NSLog(@"Error while Opening Databse. %s", sqlite3_errmsg(database));
    }

1 个答案:

答案 0 :(得分:1)

MainBundle只读。您无法修改Bundle中的文件。

您需要将数据库文件复制到文档目录,并且需要从那里进行读写。不是来自Bundle。