From 2efda8feab3bb3e6534f7f0c7b2ea103e429ff9d Mon Sep 17 00:00:00 2001 From: mtvee Date: Wed, 10 Jun 2009 11:09:37 +0000 Subject: update dot file genertor to use SPTableData instead of a v5 style query for fk relations --- Source/SPTableData.m | 1 + Source/TableDump.m | 40 +++++++++++++++++++++------------------- 2 files changed, 22 insertions(+), 19 deletions(-) (limited to 'Source') diff --git a/Source/SPTableData.m b/Source/SPTableData.m index d01dd4cd..5657dd2c 100644 --- a/Source/SPTableData.m +++ b/Source/SPTableData.m @@ -522,6 +522,7 @@ tableData = [NSMutableDictionary dictionary]; [tableData setObject:[NSString stringWithString:encodingString] forKey:@"encoding"]; [tableData setObject:[NSArray arrayWithArray:tableColumns] forKey:@"columns"]; + [tableData setObject:[NSArray arrayWithArray:constraints] forKey:@"constraints"]; [encodingString release]; [tableColumns release]; diff --git a/Source/TableDump.m b/Source/TableDump.m index 5466f42f..985564fd 100644 --- a/Source/TableDump.m +++ b/Source/TableDump.m @@ -1172,12 +1172,14 @@ previousConnectionEncoding = [tableDocumentInstance connectionEncoding]; previousConnectionEncodingViaLatin1 = [tableDocumentInstance connectionEncodingViaLatin1]; + NSMutableArray *fkInfo = [[NSMutableArray alloc] init]; // tables here for ( int i = 0 ; i < [tables count] ; i++ ) { NSString *tableName = [[tables objectAtIndex:i] objectAtIndex:1]; - + NSDictionary *tinfo = [tableDataInstance informationForTable:tableName]; + [singleProgressText setStringValue:[NSString stringWithFormat:NSLocalizedString(@"Table %i of %i (%@): Fetching data...", @"text showing that app is fetching data for table dump"), (i+1), [tables count], tableName]]; [singleProgressText displayIfNeeded]; [singleProgressBar setIndeterminate:YES]; @@ -1192,21 +1194,27 @@ [metaString appendString:[NSString stringWithFormat:@"\t\t\t%@\n", tableName]]; // grab column info - CMMCPResult *theResult = [[mySQLConnection queryString:[NSString stringWithFormat:@"SHOW COLUMNS FROM %@", [tableName backtickQuotedString]]] retain]; - - if ([theResult numOfRows]) - [theResult dataSeek:0]; - for ( int j = 0 ; j < [theResult numOfRows] ; j++ ) { - NSMutableDictionary *tempRow = [NSMutableDictionary dictionaryWithDictionary:[theResult fetchRowAsDictionary]]; - [metaString appendString:[NSString stringWithFormat:@"\t\t\t%@:%@\n", [tempRow objectForKey:@"Field"], [tempRow objectForKey:@"Field"], [tempRow objectForKey:@"Type"]]]; + NSArray *cinfo = [tinfo objectForKey:@"columns"]; + for( int j = 0; j < [cinfo count]; j++ ) { + [metaString appendString:[NSString stringWithFormat:@"\t\t\t%@:%@\n", [[cinfo objectAtIndex:j] objectForKey:@"name"], [[cinfo objectAtIndex:j] objectForKey:@"name"], [[cinfo objectAtIndex:j] objectForKey:@"type"]]]; } - [theResult release]; - [metaString appendString:@"\t\t\t>\n"]; [metaString appendString:@"\t\t];\n"]; [metaString appendString:@"\t}\n"]; [fileHandle writeData:[metaString dataUsingEncoding:NSUTF8StringEncoding]]; + + // see about relations + cinfo = [tinfo objectForKey:@"constraints"]; + for( int j = 0; j < [cinfo count]; j++ ) { + [fkInfo addObject:[NSString stringWithFormat:@"%@:%@ -> %@:%@", + tableName, + [[cinfo objectAtIndex:j] objectForKey:@"columns"], + [[cinfo objectAtIndex:j] objectForKey:@"ref_table"], + [[cinfo objectAtIndex:j] objectForKey:@"ref_columns"] + ]]; + } + } [singleProgressText setStringValue:NSLocalizedString(@"Fetching relations...", @"text showing that app is fetching data")]; @@ -1218,17 +1226,11 @@ [metaString setString:@"edge [ arrowhead=inv, arrowtail=normal, style=dashed, color=\"#444444\" ];\n"]; // grab the relations - CMMCPResult *theResult = [[mySQLConnection queryString: - [NSString stringWithFormat:@"SELECT CONCAT( table_name, ':' , column_name, ' -> ', referenced_table_name, ':', referenced_column_name ) AS list_of_fks FROM information_schema.KEY_COLUMN_USAGE WHERE REFERENCED_TABLE_SCHEMA = ('%@') AND REFERENCED_TABLE_NAME is not null ORDER BY TABLE_NAME, COLUMN_NAME", - [tableDocumentInstance database]]] retain]; - - if ([theResult numOfRows]) - [theResult dataSeek:0]; - for ( int i = 0 ; i < [theResult numOfRows] ; i++ ) { - [metaString appendString:[NSString stringWithFormat:@"%@;\n", [[theResult fetchRowAsDictionary] objectForKey:@"list_of_fks"]]]; + for( int i = 0; i < [fkInfo count]; i++ ) { + [metaString appendString:[NSString stringWithFormat:@"%@;\n", [fkInfo objectAtIndex:i]]]; } - [theResult release]; + [fkInfo release]; // done [metaString appendString:@"}\n"]; -- cgit v1.2.3