From f54791648b44925321f2d9c631d9782574fecf51 Mon Sep 17 00:00:00 2001 From: mtvee Date: Thu, 11 Jun 2009 00:20:00 +0000 Subject: updated dot generator to handle multi-col fk's with a different arrow type and views as a different header color --- Source/SPTableData.m | 3 +++ Source/TableDump.m | 23 +++++++++++++++++++---- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/Source/SPTableData.m b/Source/SPTableData.m index a5e29a9d..f2e0c77e 100644 --- a/Source/SPTableData.m +++ b/Source/SPTableData.m @@ -317,6 +317,7 @@ // Retrieve the table syntax string NSArray *syntaxResult = [theResult fetchRowAsArray]; + NSArray *resultFieldNames = [theResult fetchFieldNames]; if ([[syntaxResult objectAtIndex:1] isKindOfClass:[NSData class]]) { tableCreateSyntax = [[NSString alloc] initWithData:[syntaxResult objectAtIndex:1] encoding:[mySQLConnection encoding]]; @@ -520,6 +521,8 @@ [fieldParser release]; tableData = [NSMutableDictionary dictionary]; + // this will be 'Table' or 'View' + [tableData setObject:[resultFieldNames objectAtIndex:0] forKey:@"type"]; [tableData setObject:[NSString stringWithString:encodingString] forKey:@"encoding"]; [tableData setObject:[NSArray arrayWithArray:tableColumns] forKey:@"columns"]; [tableData setObject:[NSArray arrayWithArray:constraints] forKey:@"constraints"]; diff --git a/Source/TableDump.m b/Source/TableDump.m index 985564fd..a309c22a 100644 --- a/Source/TableDump.m +++ b/Source/TableDump.m @@ -1186,12 +1186,16 @@ [singleProgressBar setUsesThreadedAnimation:YES]; [singleProgressBar startAnimation:self]; + NSString *hdrColor = @"#DDDDDD"; + if( [[tinfo 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", tableName]]; + [metaString appendString:[NSString stringWithFormat:@"\t\t\t\n", hdrColor, tableName]]; // grab column info NSArray *cinfo = [tinfo objectForKey:@"columns"]; @@ -1207,11 +1211,22 @@ // see about relations cinfo = [tinfo objectForKey:@"constraints"]; for( int j = 0; j < [cinfo count]; j++ ) { - [fkInfo addObject:[NSString stringWithFormat:@"%@:%@ -> %@:%@", + // get the column refs. these can be comma separated. + NSString *ccol = [[cinfo objectAtIndex:j] objectForKey:@"columns"]; + NSString *rcol = [[cinfo objectAtIndex:j] objectForKey:@"ref_columns"]; + NSString *extra = @""; + NSArray *tc = [ccol componentsSeparatedByString:@","]; + if( [tc count] > 1 ) { + extra = @" [ arrowhead=crow, arrowtail=odiamond ]"; + ccol = [tc objectAtIndex:0]; + rcol = [[ccol componentsSeparatedByString:@","] objectAtIndex:0]; + } + [fkInfo addObject:[NSString stringWithFormat:@"%@:%@ -> %@:%@ %@", tableName, - [[cinfo objectAtIndex:j] objectForKey:@"columns"], + ccol, [[cinfo objectAtIndex:j] objectForKey:@"ref_table"], - [[cinfo objectAtIndex:j] objectForKey:@"ref_columns"] + rcol, + extra ]]; } -- cgit v1.2.3
%@
%@