即使结果具有值,控制也不会在循环[结果下一个]内部进入

时间:2015-02-27 13:35:51

标签: ios objective-c fmdb

我在iOS中使用FMDB执行搜索查询操作。如果我打印结果的值,它会显示一些值,但是循环时控件不会进入。这是我的代码。

tempStr是搜索框的值:

FMResultSet *results=[db executeQuery:@"select * From Notes where Note_Title LIKE '@%'",tempStr];
marrDataDB=[[NSMutableArray alloc] init];
NSLog(@"Results for query : %@ ",results);
while ([results next])
{
    NSLog(@"I am in WHile LOOP");
    searchHelper=[[dbHelper alloc]init];

    helper.nTitle=[results stringForColumn:@"Note_Title"];
    searchHelper.nDesc=[results stringForColumn:@"Note_Desc"];
    searchHelper.nATime= [results stringForColumn:@"Note_A_Time"];

    [marrDataDB addObject:searchHelper];

}

提前致谢

2 个答案:

答案 0 :(得分:1)

如果这是真实的代码,那么查询有一个拼写错误,应该是:

@"select * From Notes where Note_Title LIKE '%@'"

所以我猜你会得到一个有效的FMResultSet对象,你会记录但是它没有包含任何实际结果,因为查询与任何内容都不匹配。

答案 1 :(得分:1)

只是检查出你是否从数据库得到任何结果

NSUInteger count = [db intForQuery:@"select count(Note_Title) From Notes where Note_Title LIKE '@%'",tempStr];
NSLog(@"count :%d",count);