FMDB结果集进入字典

时间:2012-02-22 23:46:06

标签: objective-c sqlite fmdb

是否有一种简单的方法可以将executeQuery:SELECT * ...的FMDB结果轻松地放入字典中?

FMResultSet *appointmentResults = [[DataClass getDB] executeQuery:@"SELECT * FROM Appointments WHERE date = ?",currDateString];
while ([appointmentResults next]) {
    //Create dictionary
    //Add dictionary to array for later use
}

我想知道是否有一种方法可以使字典键为列名,值为列值。最好不必在一段时间内完成每一行的循环。

1 个答案:

答案 0 :(得分:27)

是的:

NSMutableArray *results = [NSMutableArray array];

FMResultSet *appointmentResults = [[DataClass getDB] executeQuery:@"SELECT * FROM Appointments WHERE date = ?",currDateString];
while ([appointmentResults next]) {
  [results addObject:[appointmentResults resultDictionary]];
}

-resultDictionaryFMResultSet上的内置方法,它将当前元组转换为NSDictionary,以列名称为键。