Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

FMDB resultset into dictionary

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.

like image 322
Bot Avatar asked Feb 22 '12 23:02

Bot


1 Answers

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.

like image 61
Dave DeLong Avatar answered Nov 15 '22 19:11

Dave DeLong