我无法从 FMDB 捕获空结果集。代码如下。我从数据库打开和关闭以及 NSLog "1" 中获取 NSLog,但在 If 语句中没有一个!如果我在数据库中有数据很好,但如果数据库为空,我想捕获和编辑结果。
[self openDatabase];
NSNumberFormatter *nfcurrency = [[NSNumberFormatter alloc]init];
[nfcurrency setNumberStyle:NSNumberFormatterCurrencyStyle];
[nfcurrency setLocale:[NSLocale currentLocale]];
FMResultSet *result = [[self getDatabase]executeQuery:@"SELECT BFNeeded FROM tblBets ORDER BY pk DESC LIMIT 1,1;"];
//FMResultSet *result = [[self getDatabase]executeQuery:@"SELECT BFNeeded FROM tblBets ORDER BY pk DESC LIMIT 1,1;"];
NSLog(@"1");
if (result == NULL) {
NSLog(@"Last BFNeeded Result = nil");
} else {
while ([result next]) {
NSLog(@"HERE");
NSString *lastBFNeeded = [nfcurrency stringFromNumber:[NSNumber numberWithDouble:[result doubleForColumn:@"BFNeeded"]]];
NSLog(@"lastBFNeeded=%@",lastBFNeeded);
}
}
NSLog(@"ClosingDB");
[self closeDatabase];
收到第一个回复后继续:
我无法让 hasAnotherRow 按预期工作。我有这个代码:
FMResultSet *result = [[self getDatabase]executeQuery:@"SELECT BFNeeded FROM tblBets ORDER BY pk DESC LIMIT 0,1;"];
if (result == nil) {
NSLog(@"Last BFNeeded Result = nil");
}
else {
NSLog(@"has results1: %@", [result hasAnotherRow] ? @"YES" : @"NO");
while ([result next]) {
NSLog(@"has results2: %@", [result hasAnotherRow] ? @"YES" : @"NO");
}
}
对于返回结果的数据库,我得到 result1 NO, result2 YES 所以我假设 hasAnotherRow 必须进入 while ([result next]) 循环。但是,对于一个空数据库,我得到了 result1 NO,它甚至没有得到 result2!