http://www.th7.cn/Program/IOS/201406/213907.shtml
多线程操作sqlite数据库,使用FMDataBaseQueue 返回一个值。
1,返回数组
NSMutableArray *myArray = [NSMutableArray array]; [manageQueue.dbQueue inDatabase:^(FMDatabase *db) { FMResultSet *rs = [db executeQuery:selectSql]; while ([rs next]) { ... ... [myArray addObject:object]; } [rs close]; }];
2.返回NSInteger、BOOL 或者其他
__block NSInteger total = 0; [manageQueue.dbQueue inDatabase:^(FMDatabase *db) { FMResultSet *rs = [db executeQuery:selectSql]; if ([rs next]) { total = [[rs stringForColumnIndex:0] integerValue]; } [rs close]; }]; return total;
3.个人测试得出 貌似使用FMDataBaseQueue 不能在inDataBase:^(FMDatabase 8db) {} 里面返回FMResultSet 对象;当我返回FMResultSet 对象时,老是出现 Error calling sqlite3_step (21: out of memory) rs 错误。我不知道是不是因为返回FMResultSet 对象 。等大神来给我解答。。。