SQLite3选择适用于模拟器,但它不在设备上

时间:2012-11-14 12:23:46

标签: iphone ios ios5 sqlite ios-simulator

我将一组值存储在一个包含多个不同类型列的表中,当我在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中。我怎么能检查设备上发生了什么?有人经历过类似的事情吗?

谢谢!

2 个答案:

答案 0 :(得分:0)

我认为问题可能是由空记录引起的,if nil无效,请尝试NULL

if ((char *)sqlite3_column_text(compiledStatement, 1) == NULL)
 userData.Name = @"";

答案 1 :(得分:0)

我终于按照你的所有建议开始工作,我认为最终解决问题的是案例敏感的事情。谢谢大家

相关问题