FMDB resultset into dictionary

2019-03-15 14:04发布

Is there an easy way to get the FMDB results of an executeQuery:SELECT * ... easily into a dictionary?

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

I was wondering if there was a way I could make the dictionary keys the column names and the values the column values. Preferably without having to do a loop through every row inside the while.

1条回答
冷血范
2楼-- · 2019-03-15 15:08

Yep:

NSMutableArray *results = [NSMutableArray array];

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

-resultDictionary is a built-in method on FMResultSet that will turn the current tuple into an NSDictionary, keyed by column name.

查看更多
登录 后发表回答