可能的FMDatabase/FMResultSet错误

Bar*_*obs 2 macos cocoa fmdb

即使我很少遇到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"]);
}
Run Code Online (Sandbox Code Playgroud)

奇怪的是,这一切都运行正常,但我想安全地使用[db hasAnotherRow]使用if语句在while循环之前,但即使结果集包含结果,也会返回NO.

当我将生成的字典(使用FMResultSet的resultDict方法)记录到控制台时,我收到来自FMResultSet的警告"警告:此集合中似乎没有列." 即使我可以在我的while循环中使用它们.

我在这里错过了什么吗?

Gre*_* M. 16

您必须在调用[resultSet resultDict]之前调用[resultSet next],否则结果中的指针位于第一行之前.这也是你的循环工作的原因,但你对hasAnotherRow的检查没有.