可能的 FMDatabase/FMResultSet 错误
尽管我很少遇到 FMDatabase 问题,但今天我注意到一些奇怪的行为,并想知道这是一个错误还是由于我自己的错误造成的。
NSString *query = [NSString stringWithFormat:@"SELECT * FROM TABLE_A WHERE modelId = %lu", modelId];
FMResultSet *resultSet = [db executeQuery:query];
while ([resultSetIPTCProperties next]) {
NSLog(@"MODEL ID: %lu", [resultSetIPTCProperties intForColumn:@"stringId"]);
}
奇怪的是,这一切都工作正常,但我想安全起见,并在 while 循环之前使用 [db hasAnotherRow] 的 if 语句,但即使结果集确实包含结果,也会返回 NO。
当我将生成的字典(使用 FMResultSet 的 resultDict 方法)记录到控制台时,我收到来自 FMResultSet 的警告,提示“警告:此集中似乎没有列。”即使我可以在 while 循环中使用它们。
我在这里错过了什么吗?
Even though I rarely have problems with FMDatabase, I noticed some odd behavior today and was wondering if this is a bug or due to a mistake of my own.
NSString *query = [NSString stringWithFormat:@"SELECT * FROM TABLE_A WHERE modelId = %lu", modelId];
FMResultSet *resultSet = [db executeQuery:query];
while ([resultSetIPTCProperties next]) {
NSLog(@"MODEL ID: %lu", [resultSetIPTCProperties intForColumn:@"stringId"]);
}
The odd thing is that this all works fine, but I wanted to play safe and precede the while loop with an if statement using [db hasAnotherRow], but this returns NO even when the result set does contain results.
When I log the resulting dictionary (using FMResultSet's resultDict method) to the console, I get a warning from FMResultSet saying "Warning: There seem to be no columns in this set." even though I can use them in my while loop.
Am I missing something here?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您必须先调用 [resultSet next],然后才能调用 [resultSet resultDict],否则结果中的指针位于第一行之前。这也是为什么你的循环有效,但你对 hasAnotherRow 的检查却不起作用。
You have to call [resultSet next] before you can call [resultSet resultDict] otherwise the pointer in the result is before the first row. This is also why your loop works, but your check for hasAnotherRow does not.