diff options
Diffstat (limited to 'Classes/SourcesEditViewController.m')
-rw-r--r-- | Classes/SourcesEditViewController.m | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/Classes/SourcesEditViewController.m b/Classes/SourcesEditViewController.m index 070b8a8..34a299f 100644 --- a/Classes/SourcesEditViewController.m +++ b/Classes/SourcesEditViewController.m @@ -53,8 +53,8 @@ db = [[FMDatabase databaseWithPath:[PicCastAppDelegate getDatabasePath]] retain]; [db setShouldCacheStatements:YES]; -// [db setTraceExecution:true]; -// [db setLogsErrors:true]; + [db setTraceExecution:true]; + [db setLogsErrors:true]; [self loadSourcesFromDb]; @@ -78,7 +78,7 @@ FMResultSet *result = [db executeQuery:@"SELECT * FROM subscribedSources"]; while ([result next]) { Source *source = [Source initFromDatabaseRow:result]; - [sectionDictionary appendObject:source forKey:@"Potpourri"]; + [sectionDictionary appendObject:source forKey:source.category]; } [db close]; } @@ -126,12 +126,13 @@ - (void) addSourcesFromJson:(NSData *)data { NSError *theError = nil; - id array = [[CJSONDeserializer deserializer] deserialize:(NSData *)data error:&theError]; + id dictionary = [[CJSONDeserializer deserializer] deserialize:(NSData *)data error:&theError]; + NSArray *array = [dictionary objectForKey:@"list"]; //NSLog(@"class: %@", [array class]); [db open]; for (NSDictionary *obj in array) { - NSLog(@"foreign key: %d", [obj objectForKey:@"pk"]); - FMResultSet *result = [db executeQuery:@"SELECT * FROM subscribedSources WHERE foreignId = ?", [obj objectForKey:@"pk"]]; + NSLog(@"foreign key: %d", [obj objectForKey:@"id"]); + FMResultSet *result = [db executeQuery:@"SELECT * FROM subscribedSources WHERE foreignId = ?", [obj objectForKey:@"id"]]; if (![result next]) { NSLog(@"found source"); Source *source = [Source initWithJsonObject:obj]; @@ -259,12 +260,12 @@ // method is sent after switch actually gets switched, so the state is what we want it to be MyButton *switcher = (MyButton *)sender; NSIndexPath *indexPath = switcher.indexPath; - NSInteger foreignId = [[[sectionDictionary objectForIndex:indexPath.section] objectAtIndex:indexPath.row] foreignId]; + NSNumber *foreignId = [[[sectionDictionary objectForIndex:indexPath.section] objectAtIndex:indexPath.row] foreignId]; NSLog(@"number %d", foreignId); [db open]; [db beginTransaction]; - [db executeUpdate:@"UPDATE subscribedSources SET subscribed = ? WHERE foreignId = ?", [NSNumber numberWithInt:(switcher.on ? 1 : 0)], [NSNumber numberWithInt:foreignId]]; + [db executeUpdate:@"UPDATE subscribedSources SET subscribed = ? WHERE foreignId = ?", [NSNumber numberWithInt:(switcher.on ? 1 : 0)], foreignId]; [db commit]; [db close]; } |