1

我目前正在为 iphone 开发一款游戏,其中图像是从互联网加载的,然后存储在本地数据库中,因此不必再次加载它们。这一直运作良好。最近我为测试组创建了一个新的 adhoc 发行版(我第一次使用 SDK 3.1.2 创建发行版)现在已经将他们的 iphone 升级到 3.1.2 的每个人都不再能够写入数据库了,因此每次都必须从互联网上加载图像。iphone 版本低于 3.1.2 的人没有问题,以前构建的版本(SDK 3.1 或更低)在 3.1.2 的 iphone 上没有问题。我对游戏所做的更新与游戏中的数据管理器无关。另一个奇怪的事情是,我没有在控制台中使用以下代码找到任何消息:

- (void) saveImage:(NSString *)imagePath withData:(NSData *)imageData {
    if (insert_image_statement == nil){
        const char *sql2 = "INSERT INTO image (imagePath, imageData) VALUES (?, ?);";
        if (sqlite3_prepare_v2(database, sql2, -1, &insert_image_statement, NULL) != SQLITE_OK) {
            NSLog(@"Error: failed to prepare statement with message '%s'.", sqlite3_errmsg(database));
        }
    }
    sqlite3_bind_text(insert_image_statement, 1, [imagePath UTF8String], -1, NULL);
    sqlite3_bind_blob(insert_image_statement, 2, [imageData bytes], [imageData length], NULL);
    int success = sqlite3_step(insert_image_statement);
    if (success == SQLITE_ERROR){
        NSLog(@"Error: failed to insert statement with message '%s'.", sqlite3_errmsg(database));
    }
    sqlite3_reset(insert_image_statement);
}

所以 sqlite3 不会抛出错误,这可能会指向我解决这个问题的方法。有人知道为什么使用 SDK 3.1.2 我似乎无权将数据写入数据库吗?

4

1 回答 1

0

这个问题解决了吗?我在 3.1.2 中的 Device/Release 版本中遇到了类似的问题,在 if(sqlite3_exec(...)); 中抛出了错误。语句,但不返回错误信息。

********更新:通过修改引用以包含设备上的完整路径,达到了部分解决方案。谷歌“checkAndCreateDatabase”方法的代码。我在 3.1.2 操作系统中的设备上的 sqlite prepare 语句仍然有失败,而我在模拟器中没有。**********

-(void)initializeDatabaseFunctions {

databaseName = "RowTable.db";
returnCode = sqlite3_open(databaseName, &sqlite);

NSString *dropRows = [[NSString alloc]initWithFormat:@"DROP TABLE IF EXISTS rows;"];
if(sqlite3_exec(sqlite, [dropRows UTF8String], NULL, NULL, &errorMsg) != SQLITE_OK) {
    NSLog(@"Error DROP TABLE IF EXISTS rows: %s", errorMsg);
sqlite3_free(errorMsg);}
于 2010-01-02T21:12:23.463 回答