我无法捕获FMDB中的空结果集。 代码如下。我从数据库打开和关闭NSLog和NSLog“1”,但没有在If语句中的! 如果我有数据库中的数据很好,但我想陷阱和编辑结果,如果数据库是空的。我无法捕获FMDB空结果集
[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,YES RESULT2所以我承担hasAnotherRow必须要走的一段时间([结果旁边])循环中。 但是,对于空数据库,我得到了result1 NO,它甚至没有得到result2!
非常感谢。我不知道hasAnotherRow。 – Darren 2011-12-15 13:02:02