![](/img/trans.png)
[英]sqlite3 query works on cmd line but returns no data in iOS 6 SImulator
[英]SQLite3 selection works on simulator but it does not on device
我将值的集合存储在具有不同类型的几列的表中,并且当我在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中却不是。 我如何检查设备上正在发生的事情? 有人经历过类似的事情吗?
谢谢!
我认为问题可能是由空记录引起的, if nil
您的if nil
无效,请尝试使用NULL
:
if ((char *)sqlite3_column_text(compiledStatement, 1) == NULL)
userData.Name = @"";
我终于按照您的所有建议使其工作了,我认为最终解决问题的是区分大小写的事情。 谢谢大家
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.