From 9eb3012a29eb9adb658159c984716971f0141446 Mon Sep 17 00:00:00 2001 From: stuconnolly Date: Thu, 27 May 2010 22:35:43 +0000 Subject: Remove unsed try/catch exception blocks in all data exporters. --- Source/SPDotExporter.m | 239 ++++++++++++++++++++++++------------------------- 1 file changed, 118 insertions(+), 121 deletions(-) (limited to 'Source/SPDotExporter.m') diff --git a/Source/SPDotExporter.m b/Source/SPDotExporter.m index cbb132d9..044065e5 100644 --- a/Source/SPDotExporter.m +++ b/Source/SPDotExporter.m @@ -61,150 +61,147 @@ */ - (void)main { - @try { - NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; - - NSMutableString *metaString = [NSMutableString string]; - - // Check that we have all the required info before starting the export - if ((![self dotExportTables]) || (![self dotTableData]) || ([[self dotExportTables] count] == 0)) { + NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init]; + + NSMutableString *metaString = [NSMutableString string]; + + // Check that we have all the required info before starting the export + if ((![self dotExportTables]) || (![self dotTableData]) || ([[self dotExportTables] count] == 0)) { + [pool release]; + return; + } + + // Inform the delegate that the export process is about to begin + [delegate performSelectorOnMainThread:@selector(dotExportProcessWillBegin:) withObject:self waitUntilDone:NO]; + + // Mark the process as running + [self setExportProcessIsRunning:YES]; + + [metaString setString:@"// ************************************************************\n"]; + [metaString appendString:@"// Generated by: Sequel Pro\n"]; + [metaString appendString:[NSString stringWithFormat:@"// Version %@\n//\n", [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleVersion"]]]; + [metaString appendString:[NSString stringWithFormat:@"// %@\n// %@\n//\n", SPHomePageURL, SPDevURL]]; + [metaString appendString:[NSString stringWithFormat:@"// Host: %@ (MySQL %@)\n", [self dotDatabaseHost], [self dotDatabaseVersion]]]; + [metaString appendString:[NSString stringWithFormat:@"// Database: %@\n", [self dotDatabaseName]]]; + [metaString appendString:[NSString stringWithFormat:@"// Generation Time: %@\n", [NSDate date]]]; + [metaString appendString:@"// ************************************************************\n\n"]; + + [metaString appendString:@"digraph \"Database Structure\" {\n"]; + [metaString appendString:[NSString stringWithFormat:@"\tlabel = \"ER Diagram: %@\";\n", [self dotDatabaseName]]]; + [metaString appendString:@"\tlabelloc = t;\n"]; + [metaString appendString:@"\tcompound = true;\n"]; + [metaString appendString:@"\tnode [ shape = record ];\n"]; + [metaString appendString:@"\tfontname = \"Helvetica\";\n"]; + [metaString appendString:@"\tranksep = 1.25;\n"]; + [metaString appendString:@"\tratio = 0.7;\n"]; + [metaString appendString:@"\trankdir = LR;\n"]; + + // Write information to the file + [[self exportOutputFileHandle] writeData:[metaString dataUsingEncoding:NSUTF8StringEncoding]]; + + NSMutableArray *fkInfo = [[NSMutableArray alloc] init]; + + // Process the tables + for (NSInteger i = 0; i < [[self dotExportTables] count]; i++) + { + // Check for cancellation flag + if ([self isCancelled]) { [pool release]; return; } + + NSString *tableName = NSArrayObjectAtIndex([self dotExportTables], i); + NSDictionary *tableInfo = [[self dotTableData] informationForTable:tableName]; + + // Set the current table + [self setDotExportCurrentTable:tableName]; + + // Inform the delegate that we are about to start fetcihing data for the current table + [delegate performSelectorOnMainThread:@selector(dotExportProcessWillBeginFetchingData:) withObject:self waitUntilDone:NO]; + + NSString *hdrColor = @"#DDDDDD"; + + if ([[tableInfo objectForKey:@"type"] isEqualToString:@"View"]) { + hdrColor = @"#DDDDFF"; + } - // Inform the delegate that the export process is about to begin - [delegate performSelectorOnMainThread:@selector(dotExportProcessWillBegin:) withObject:self waitUntilDone:NO]; + [metaString setString:[NSString stringWithFormat:@"\tsubgraph \"table_%@\" {\n", tableName]]; + [metaString appendString:@"\t\tnode [ shape = \"plaintext\" ];\n"]; + [metaString appendString:[NSString stringWithFormat:@"\t\t\"%@\" [ label=<\n", tableName]]; + [metaString appendString:@"\t\t\t\n"]; + [metaString appendString:[NSString stringWithFormat:@"\t\t\t\n", hdrColor, tableName]]; - // Mark the process as running - [self setExportProcessIsRunning:YES]; + // Get the column info + NSArray *columnInfo = [tableInfo objectForKey:@"columns"]; - [metaString setString:@"// ************************************************************\n"]; - [metaString appendString:@"// Generated by: Sequel Pro\n"]; - [metaString appendString:[NSString stringWithFormat:@"// Version %@\n//\n", [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleVersion"]]]; - [metaString appendString:[NSString stringWithFormat:@"// %@\n// %@\n//\n", SPHomePageURL, SPDevURL]]; - [metaString appendString:[NSString stringWithFormat:@"// Host: %@ (MySQL %@)\n", [self dotDatabaseHost], [self dotDatabaseVersion]]]; - [metaString appendString:[NSString stringWithFormat:@"// Database: %@\n", [self dotDatabaseName]]]; - [metaString appendString:[NSString stringWithFormat:@"// Generation Time: %@\n", [NSDate date]]]; - [metaString appendString:@"// ************************************************************\n\n"]; + for (NSInteger j = 0; j < [columnInfo count]; j++ ) + { + [metaString appendString:[NSString stringWithFormat:@"\t\t\t\n", [[columnInfo objectAtIndex:j] objectForKey:@"name"], [[columnInfo objectAtIndex:j] objectForKey:@"name"], [[columnInfo objectAtIndex:j] objectForKey:@"type"]]]; + } - [metaString appendString:@"digraph \"Database Structure\" {\n"]; - [metaString appendString:[NSString stringWithFormat:@"\tlabel = \"ER Diagram: %@\";\n", [self dotDatabaseName]]]; - [metaString appendString:@"\tlabelloc = t;\n"]; - [metaString appendString:@"\tcompound = true;\n"]; - [metaString appendString:@"\tnode [ shape = record ];\n"]; - [metaString appendString:@"\tfontname = \"Helvetica\";\n"]; - [metaString appendString:@"\tranksep = 1.25;\n"]; - [metaString appendString:@"\tratio = 0.7;\n"]; - [metaString appendString:@"\trankdir = LR;\n"]; + [metaString appendString:@"\t\t\t
%@
%@:%@
>\n"]; + [metaString appendString:@"\t\t];\n"]; + [metaString appendString:@"\t}\n"]; - // Write information to the file [[self exportOutputFileHandle] writeData:[metaString dataUsingEncoding:NSUTF8StringEncoding]]; - - NSMutableArray *fkInfo = [[NSMutableArray alloc] init]; - // Process the tables - for (NSInteger i = 0; i < [[self dotExportTables] count]; i++) + // see about relations + columnInfo = [tableInfo objectForKey:@"constraints"]; + + for (NSInteger j = 0; j < [columnInfo count]; j++) { // Check for cancellation flag if ([self isCancelled]) { [pool release]; return; } - - NSString *tableName = NSArrayObjectAtIndex([self dotExportTables], i); - NSDictionary *tableInfo = [[self dotTableData] informationForTable:tableName]; - - // Set the current table - [self setDotExportCurrentTable:tableName]; - - // Inform the delegate that we are about to start fetcihing data for the current table - [delegate performSelectorOnMainThread:@selector(dotExportProcessWillBeginFetchingData:) withObject:self waitUntilDone:NO]; - - NSString *hdrColor = @"#DDDDDD"; - - if ([[tableInfo objectForKey:@"type"] isEqualToString:@"View"]) { - hdrColor = @"#DDDDFF"; - } - [metaString setString:[NSString stringWithFormat:@"\tsubgraph \"table_%@\" {\n", tableName]]; - [metaString appendString:@"\t\tnode [ shape = \"plaintext\" ];\n"]; - [metaString appendString:[NSString stringWithFormat:@"\t\t\"%@\" [ label=<\n", tableName]]; - [metaString appendString:@"\t\t\t\n"]; - [metaString appendString:[NSString stringWithFormat:@"\t\t\t\n", hdrColor, tableName]]; + // Get the column references. Currently the columns themselves are an array, + // while reference columns and tables are comma separated if there are more than + // one. Only use the first of each for the time being. + NSArray *ccols = [NSArrayObjectAtIndex(columnInfo, j) objectForKey:@"columns"]; + NSString *ccol = NSArrayObjectAtIndex(columnInfo, 0); + NSString *rcol = [NSArrayObjectAtIndex(columnInfo, j) objectForKey:@"ref_columns"]; - // Get the column info - NSArray *columnInfo = [tableInfo objectForKey:@"columns"]; + NSString *extra = @""; - for (NSInteger j = 0; j < [columnInfo count]; j++ ) - { - [metaString appendString:[NSString stringWithFormat:@"\t\t\t\n", [[columnInfo objectAtIndex:j] objectForKey:@"name"], [[columnInfo objectAtIndex:j] objectForKey:@"name"], [[columnInfo objectAtIndex:j] objectForKey:@"type"]]]; + if ([ccols count] > 1) { + extra = @" [ arrowhead=crow, arrowtail=odiamond ]"; + rcol = NSArrayObjectAtIndex([rcol componentsSeparatedByString:@","], 0); } - [metaString appendString:@"\t\t\t
%@
%@:%@
>\n"]; - [metaString appendString:@"\t\t];\n"]; - [metaString appendString:@"\t}\n"]; - - [[self exportOutputFileHandle] writeData:[metaString dataUsingEncoding:NSUTF8StringEncoding]]; - - // see about relations - columnInfo = [tableInfo objectForKey:@"constraints"]; - - for (NSInteger j = 0; j < [columnInfo count]; j++) - { - // Check for cancellation flag - if ([self isCancelled]) { - [pool release]; - return; - } - - // Get the column references. Currently the columns themselves are an array, - // while reference columns and tables are comma separated if there are more than - // one. Only use the first of each for the time being. - NSArray *ccols = [NSArrayObjectAtIndex(columnInfo, j) objectForKey:@"columns"]; - NSString *ccol = NSArrayObjectAtIndex(columnInfo, 0); - NSString *rcol = [NSArrayObjectAtIndex(columnInfo, j) objectForKey:@"ref_columns"]; - - NSString *extra = @""; - - if ([ccols count] > 1) { - extra = @" [ arrowhead=crow, arrowtail=odiamond ]"; - rcol = NSArrayObjectAtIndex([rcol componentsSeparatedByString:@","], 0); - } - - [fkInfo addObject:[NSString stringWithFormat:@"%@:%@ -> %@:%@ %@", tableName, ccol, [NSArrayObjectAtIndex(columnInfo, j) objectForKey:@"ref_table"], rcol, extra]]; - } + [fkInfo addObject:[NSString stringWithFormat:@"%@:%@ -> %@:%@ %@", tableName, ccol, [NSArrayObjectAtIndex(columnInfo, j) objectForKey:@"ref_table"], rcol, extra]]; } - - // Inform the delegate that we are about to start fetching relations data for the current table - [delegate performSelectorOnMainThread:@selector(dotExportProcessWillBeginFetchingRelationsData:) withObject:self waitUntilDone:NO]; - - [metaString setString:@"edge [ arrowhead=inv, arrowtail=normal, style=dashed, color=\"#444444\" ];\n"]; - - // Get the relations - for (NSInteger i = 0; i < [fkInfo count]; i++) - { - [metaString appendString:[NSString stringWithFormat:@"%@;\n", [fkInfo objectAtIndex:i]]]; - } - - [fkInfo release]; - - [metaString appendString:@"}\n"]; - - // Write information to the file - [[self exportOutputFileHandle] writeData:[metaString dataUsingEncoding:NSUTF8StringEncoding]]; - - // Write data to disk - [[self exportOutputFileHandle] closeFile]; - - // Mark the process as not running - [self setExportProcessIsRunning:NO]; - - // Inform the delegate that the export process is complete - [delegate performSelectorOnMainThread:@selector(dotExportProcessComplete:) withObject:self waitUntilDone:NO]; - - [pool release]; } - @catch (NSException *e) { } + + // Inform the delegate that we are about to start fetching relations data for the current table + [delegate performSelectorOnMainThread:@selector(dotExportProcessWillBeginFetchingRelationsData:) withObject:self waitUntilDone:NO]; + + [metaString setString:@"edge [ arrowhead=inv, arrowtail=normal, style=dashed, color=\"#444444\" ];\n"]; + + // Get the relations + for (NSInteger i = 0; i < [fkInfo count]; i++) + { + [metaString appendString:[NSString stringWithFormat:@"%@;\n", [fkInfo objectAtIndex:i]]]; + } + + [fkInfo release]; + + [metaString appendString:@"}\n"]; + + // Write information to the file + [[self exportOutputFileHandle] writeData:[metaString dataUsingEncoding:NSUTF8StringEncoding]]; + + // Write data to disk + [[self exportOutputFileHandle] closeFile]; + + // Mark the process as not running + [self setExportProcessIsRunning:NO]; + + // Inform the delegate that the export process is complete + [delegate performSelectorOnMainThread:@selector(dotExportProcessComplete:) withObject:self waitUntilDone:NO]; + + [pool release]; } /** -- cgit v1.2.3