Bot*_*Bot 10 sqlite objective-c fmdb
有没有一种简单的方法可以轻松地将FMDB结果executeQuery:SELECT * ...放入字典中?
FMResultSet *appointmentResults = [[DataClass getDB] executeQuery:@"SELECT * FROM Appointments WHERE date = ?",currDateString];
while ([appointmentResults next]) {
//Create dictionary
//Add dictionary to array for later use
}
Run Code Online (Sandbox Code Playgroud)
我想知道是否有一种方法可以使字典键为列名,值为列值.优选地,不必在一段时间内遍历每一行.
Dav*_*ong 27
是的:
NSMutableArray *results = [NSMutableArray array];
FMResultSet *appointmentResults = [[DataClass getDB] executeQuery:@"SELECT * FROM Appointments WHERE date = ?",currDateString];
while ([appointmentResults next]) {
[results addObject:[appointmentResults resultDictionary]];
}
Run Code Online (Sandbox Code Playgroud)
-resultDictionary是一个内置的方法FMResultSet,将当前元组转换为NSDictionary,由列名称键入.