aboutsummaryrefslogtreecommitdiffstats
path: root/Source/TableDump.m
diff options
context:
space:
mode:
authormtvee <emptyvee@gmail.com>2009-06-10 11:09:37 +0000
committermtvee <emptyvee@gmail.com>2009-06-10 11:09:37 +0000
commit2efda8feab3bb3e6534f7f0c7b2ea103e429ff9d (patch)
treedec32ba3a52f64b5aa7c8189c621f9cd3bc6578f /Source/TableDump.m
parentbea8a9f461a9a9566b28d208b47db772591ac0fa (diff)
downloadsequelpro-2efda8feab3bb3e6534f7f0c7b2ea103e429ff9d.tar.gz
sequelpro-2efda8feab3bb3e6534f7f0c7b2ea103e429ff9d.tar.bz2
sequelpro-2efda8feab3bb3e6534f7f0c7b2ea103e429ff9d.zip
update dot file genertor to use SPTableData instead of a v5 style query for fk relations
Diffstat (limited to 'Source/TableDump.m')
-rw-r--r--Source/TableDump.m40
1 files changed, 21 insertions, 19 deletions
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<TR><TD COLSPAN=\"3\" BGCOLOR=\"#DDDDDD\">%@</TD></TR>\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<TR><TD COLSPAN=\"3\" PORT=\"%@\">%@:<FONT FACE=\"Helvetica-Oblique\" POINT-SIZE=\"10\">%@</FONT></TD></TR>\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<TR><TD COLSPAN=\"3\" PORT=\"%@\">%@:<FONT FACE=\"Helvetica-Oblique\" POINT-SIZE=\"10\">%@</FONT></TD></TR>\n", [[cinfo objectAtIndex:j] objectForKey:@"name"], [[cinfo objectAtIndex:j] objectForKey:@"name"], [[cinfo objectAtIndex:j] objectForKey:@"type"]]];
}
- [theResult release];
-
[metaString appendString:@"\t\t\t</TABLE>>\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"];