0

我将一组值存储在一个包含几列不同类型的表中,当我在 iPhone 模拟器上运行应用程序时,插入和选择工作正常。但是,在真实设备上运行并选择数据时,似乎无法获取表的某些文本列(其余列似乎已正确检索)。我应该看到一个带有字符串的对话框,但我没有,我得到一个空对话框,而带有字符串的对话框正确显示在模拟器上。

这是插入的代码片段:

if(sqlite3_prepare_v2(database, sqlStatement,
                          -1, &compiledStatement, NULL) == SQLITE_OK)
    {
        sqlite3_bind_int(compiledStatement, 1, userData.ID);
        sqlite3_bind_double(compiledStatement, 2, userData.Location.Lat);
        sqlite3_bind_double(compiledStatement, 3, userData.Location.Lon);
        sqlite3_bind_text(compiledStatement, 4, [userData.Name UTF8String], -1, SQLITE_TRANSIENT);
        sqlite3_bind_text(compiledStatement, 5, [userData.Surname UTF8String], -1, SQLITE_TRANSIENT);
    }

    if(sqlite3_step(compiledStatement) == SQLITE_DONE) {
        sqlite3_finalize(compiledStatement);
    }
    else {
        NSLog(@"%d",sqlite3_step(compiledStatement));
    }
}
sqlite3_close(database);

这是选择:

if (sqlite3_prepare_v2(database, sqlStatement, -1, &compiledStatement, NULL) == SQLITE_OK) {
        while(sqlite3_step(compiledStatement) == SQLITE_ROW) {
            UserData *userData = [[UserData alloc] init];

            userData.ID = sqlite3_column_int(compiledStatement, 0);

            char *name = sqlite3_column_text(compiledStatement, 1);
            if (name == nil)
                userData.Name = @"";
            else
                userData.Name = [NSString stringWithUTF8String: name];

            [list addObject:userData];
        }
    }
    sqlite3_finalize(compiledStatement);
}
sqlite3_close(database);

我完全不知道为什么数据库数据管理在模拟器中表现良好(我有 SQLite Manager 插件并且数据被正确存储和检索),但它不是在真正的 iPhone 中。我如何检查设备上发生的情况?有人经历过类似的事情吗?

谢谢!

4

2 回答 2

0

我认为问题可能是由空记录引起的,而您if nil没有帮助,请尝试NULL

if ((char *)sqlite3_column_text(compiledStatement, 1) == NULL)
 userData.Name = @"";
于 2012-11-14T12:28:10.423 回答
0

根据您的所有建议,我终于让它工作了,我认为最终解决问题的是区分大小写的事情。谢谢你们

于 2012-11-17T10:07:26.140 回答