我正在尝试通过主要详细信息类型的表进行迭代,并且我想在进行时填充主要/详细信息结构。显然,当我嵌套结果集时,我得到一个 BAD Access 异常:
FMDatabase *db = self.database;
[db open];
db.traceExecution = YES;
db.logsErrors = YES;
FMResultSet *rs = [db executeQuery:@"select group_id, label from main.preference_group order by group_id"];
while ([rs next])
{
PreferenceGroup *pg = [[PreferenceGroup alloc] init];
pg.group_id = [rs intForColumn:@"group_id"];
pg.label = [rs stringForColumn:@"label"];
pg.translatedLabel = NSLocalizedString(pg.label, nil);
NSMutableArray * prefs = [[NSMutableArray alloc] init];
[prefGroups addObject:prefs];
FMResultSet *rs2 = [db executeQuery:@"select pref_id, label, value from main.preference where group_id = ? order by pref_id", pg.group_id, nil];
while ([rs2 next])
{
Preference * pref = [[Preference alloc] init];
pref.group_id = pg.group_id;
pref.pref_id = [rs2 intForColumn:@"pref_id"];
pref.label = [rs2 stringForColumn:@"label"];
pref.value = [rs2 stringForColumn:@"value"];
pref.translatedLabel = NSLocalizedString(pref.value, nil);
[prefs addObject:pref];
}
[rs2 close];
}
[rs close];
[db close];
在 rs2(第二个结果集)中,我得到了 FMDatabase 类中的 EXEC_BAD_ACCESS。
这是对 sqlite3/fmdb 的限制还是我在这里做错了什么?