aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Interfaces/English.lproj/MainMenu.xib48
-rw-r--r--Source/TableDump.h1
-rw-r--r--Source/TableDump.m141
3 files changed, 174 insertions, 16 deletions
diff --git a/Interfaces/English.lproj/MainMenu.xib b/Interfaces/English.lproj/MainMenu.xib
index d34c8f03..10bc76fc 100644
--- a/Interfaces/English.lproj/MainMenu.xib
+++ b/Interfaces/English.lproj/MainMenu.xib
@@ -1,28 +1,19 @@
<?xml version="1.0" encoding="UTF-8"?>
-<archive type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="7.03">
+<archive type="com.apple.InterfaceBuilder3.Cocoa.XIB" version="7.02">
<data>
<int key="IBDocument.SystemTarget">1050</int>
<string key="IBDocument.SystemVersion">9J61</string>
- <string key="IBDocument.InterfaceBuilderVersion">677</string>
+ <string key="IBDocument.InterfaceBuilderVersion">672</string>
<string key="IBDocument.AppKitVersion">949.46</string>
<string key="IBDocument.HIToolboxVersion">353.00</string>
<object class="NSMutableArray" key="IBDocument.EditedObjectIDs">
<bool key="EncodedWithXMLCoder">YES</bool>
- <integer value="504"/>
+ <integer value="930"/>
</object>
<object class="NSArray" key="IBDocument.PluginDependencies">
<bool key="EncodedWithXMLCoder">YES</bool>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
</object>
- <object class="NSMutableDictionary" key="IBDocument.Metadata">
- <bool key="EncodedWithXMLCoder">YES</bool>
- <object class="NSArray" key="dict.sortedKeys">
- <bool key="EncodedWithXMLCoder">YES</bool>
- </object>
- <object class="NSMutableArray" key="dict.values">
- <bool key="EncodedWithXMLCoder">YES</bool>
- </object>
- </object>
<object class="NSMutableArray" key="IBDocument.RootObjects" id="549353383">
<bool key="EncodedWithXMLCoder">YES</bool>
<object class="NSCustomObject" id="515727999">
@@ -322,6 +313,15 @@
<reference key="NSMixedImage" ref="315854375"/>
<int key="NSTag">5</int>
</object>
+ <object class="NSMenuItem" id="536279428">
+ <reference key="NSMenu" ref="277457689"/>
+ <string key="NSTitle">Graphviz dot file...</string>
+ <string key="NSKeyEquiv"/>
+ <int key="NSMnemonicLoc">2147483647</int>
+ <reference key="NSOnImage" ref="625762401"/>
+ <reference key="NSMixedImage" ref="315854375"/>
+ <int key="NSTag">14</int>
+ </object>
<object class="NSMenuItem" id="497310196">
<reference key="NSMenu" ref="277457689"/>
<bool key="NSIsDisabled">YES</bool>
@@ -2390,6 +2390,14 @@
</object>
<int key="connectionID">929</int>
</object>
+ <object class="IBConnectionRecord">
+ <object class="IBActionConnection" key="connection">
+ <string key="label">export:</string>
+ <reference key="source" ref="63651044"/>
+ <reference key="destination" ref="536279428"/>
+ </object>
+ <int key="connectionID">931</int>
+ </object>
</object>
<object class="IBMutableOrderedSet" key="objectRecords">
<object class="NSArray" key="orderedObjects">
@@ -2678,6 +2686,7 @@
<reference ref="44352296"/>
<reference ref="1004249038"/>
<reference ref="586592608"/>
+ <reference ref="536279428"/>
</object>
<reference key="parent" ref="258329286"/>
</object>
@@ -3565,6 +3574,11 @@
<reference key="object" ref="998300902"/>
<reference key="parent" ref="466354362"/>
</object>
+ <object class="IBObjectRecord">
+ <int key="objectID">930</int>
+ <reference key="object" ref="536279428"/>
+ <reference key="parent" ref="277457689"/>
+ </object>
</object>
</object>
<object class="NSMutableDictionary" key="flattenedProperties">
@@ -3899,6 +3913,7 @@
<string>926.IBPluginDependency</string>
<string>926.ImportedFromIB2</string>
<string>928.IBPluginDependency</string>
+ <string>930.IBPluginDependency</string>
</object>
<object class="NSMutableArray" key="dict.values">
<bool key="EncodedWithXMLCoder">YES</bool>
@@ -4002,7 +4017,7 @@
<reference ref="9"/>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<reference ref="9"/>
- <string>{{1061, 542}, {213, 113}}</string>
+ <string>{{390, 574}, {213, 133}}</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<reference ref="9"/>
<string>{{399, 465}, {213, 93}}</string>
@@ -4012,7 +4027,7 @@
<reference ref="9"/>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<reference ref="9"/>
- <string>{{768, 271}, {136, 43}}</string>
+ <string>{{603, 634}, {136, 43}}</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<reference ref="9"/>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
@@ -4022,7 +4037,7 @@
<reference ref="9"/>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<reference ref="9"/>
- <string>{{768, 211}, {136, 43}}</string>
+ <string>{{603, 574}, {136, 43}}</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<reference ref="9"/>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
@@ -4273,6 +4288,7 @@ w6gg4oaSIGZhY2FkZV0</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<reference ref="9"/>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
+ <string>com.apple.InterfaceBuilder.CocoaPlugin</string>
</object>
</object>
<object class="NSMutableDictionary" key="unlocalizedProperties">
@@ -4295,7 +4311,7 @@ w6gg4oaSIGZhY2FkZV0</string>
</object>
</object>
<nil key="sourceID"/>
- <int key="maxID">929</int>
+ <int key="maxID">931</int>
</object>
<object class="IBClassDescriber" key="IBDocument.Classes">
<object class="NSMutableArray" key="referencedPartialClassDescriptions">
diff --git a/Source/TableDump.h b/Source/TableDump.h
index 1d34e8fa..0bf7ffcc 100644
--- a/Source/TableDump.h
+++ b/Source/TableDump.h
@@ -132,6 +132,7 @@
// Export methods
- (BOOL)dumpSelectedTablesAsSqlToFileHandle:(NSFileHandle *)fileHandle;
+- (BOOL)dumpSchemaAsDotToFileHandle:(NSFileHandle *)fileHandle;
- (BOOL)writeCsvForArray:(NSArray *)array orQueryResult:(CMMCPResult *)queryResult
toFileHandle:(NSFileHandle *)fileHandle
outputFieldNames:(BOOL)firstLine terminatedBy:(NSString *)terminated
diff --git a/Source/TableDump.m b/Source/TableDump.m
index 2fe99121..94bf8af7 100644
--- a/Source/TableDump.m
+++ b/Source/TableDump.m
@@ -193,6 +193,15 @@
[savePanel setAccessoryView:exportMultipleXMLView];
contextInfo = @"exportMultipleTablesAsXML";
break;
+
+ // graphviz dot file
+ case 14:
+ [self reloadTables:self];
+ file = [NSString stringWithString:[tableDocumentInstance database]];
+ [savePanel setRequiredFileType:@"dot"];
+ contextInfo = @"exportDot";
+ break;
+
default:
ALog(@"ERROR: unknown export item with tag %d", tag);
return;
@@ -311,6 +320,10 @@
} else if ( [contextInfo isEqualToString:@"exportMultipleTablesAsXML"] ) {
success = [self exportSelectedTablesToFileHandle:fileHandle usingFormat:@"xml"];
+ // Export the tables selected in the MySQL export sheet to a file
+ } else if ( [contextInfo isEqualToString:@"exportDot"] ) {
+ success = [self dumpSchemaAsDotToFileHandle:fileHandle];
+
// Unknown operation
} else {
ALog(@"Unknown export operation: %@", [contextInfo description]);
@@ -1093,6 +1106,134 @@
}
/*
+ Dump the selected tables to a file handle in Graphviz dot format.
+ */
+- (BOOL)dumpSchemaAsDotToFileHandle:(NSFileHandle *)fileHandle
+{
+ NSMutableString *metaString = [NSMutableString string];
+ int progressBarWidth;
+ NSString *previousConnectionEncoding;
+ BOOL previousConnectionEncodingViaLatin1;
+
+ [singleProgressText setStringValue:NSLocalizedString(@"Dumping...", @"text showing that app is writing dump")];
+ [singleProgressText displayIfNeeded];
+ progressBarWidth = (int)[singleProgressBar bounds].size.width;
+ [singleProgressBar setDoubleValue:0];
+ [singleProgressBar displayIfNeeded];
+
+ // Open the progress sheet
+ [NSApp beginSheet:singleProgressSheet
+ modalForWindow:tableWindow modalDelegate:self
+ didEndSelector:nil contextInfo:nil];
+
+ [metaString setString:@"// Generated by: Sequel Pro\n"];
+ [metaString appendString:[NSString stringWithFormat:@"// Version %@\n",
+ [[NSBundle mainBundle] objectForInfoDictionaryKey:@"CFBundleVersion"]]];
+ [metaString appendString:@"// http://code.google.com/p/sequel-pro\n//\n"];
+ [metaString appendString:[NSString stringWithFormat:@"// Host: %@ (MySQL %@)\n",
+ [tableDocumentInstance host], [tableDocumentInstance mySQLVersion]]];
+ [metaString appendString:[NSString stringWithFormat:@"// Database: %@\n", [tableDocumentInstance database]]];
+ [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", [tableDocumentInstance database]]];
+ [metaString appendString:@"\tlabelloc = t;\n"];
+ [metaString appendString:@"\tcompound = true;\n"];
+ [metaString appendString:@"\tnode [ shape = record ];\n"];
+ [metaString appendString:@"\tfontsize = 11;\n"];
+ [metaString appendString:@"\tfontname = \"Helvetica\";\n"];
+ [metaString appendString:@"\tranksep = 2.5;\n"];
+ [metaString appendString:@"\tratio = 0.7;\n"];
+ [metaString appendString:@"\trankdir = global;\n"];
+
+ // Write information to the file
+ [fileHandle writeData:[metaString dataUsingEncoding:NSUTF8StringEncoding]];
+
+ // store connection encoding
+ previousConnectionEncoding = [tableDocumentInstance connectionEncoding];
+ previousConnectionEncodingViaLatin1 = [tableDocumentInstance connectionEncodingViaLatin1];
+
+
+ // tables here
+ for ( int i = 0 ; i < [tables count] ; i++ ) {
+
+ NSString *tableName = [[tables objectAtIndex:i] objectAtIndex:1];
+
+ [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];
+ [singleProgressBar setUsesThreadedAnimation:YES];
+ [singleProgressBar startAnimation:self];
+
+
+ [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<TABLE BORDER=\"0\" CELLSPACING=\"0\" CELLBORDER=\"1\">\n"];
+ [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\">%@</TD></TR>\n", [tempRow objectForKey:@"Field"]]];
+ }
+
+ [theResult release];
+
+ [metaString appendString:@"\t\t\t</TABLE>>\n"];
+ [metaString appendString:@"\t\t];\n"];
+ [metaString appendString:@"\t}\n"];
+ [fileHandle writeData:[metaString dataUsingEncoding:NSUTF8StringEncoding]];
+ }
+
+ [singleProgressText setStringValue:NSLocalizedString(@"Fetching relations...", @"text showing that app is fetching data")];
+ [singleProgressText displayIfNeeded];
+ [singleProgressBar setIndeterminate:YES];
+ [singleProgressBar setUsesThreadedAnimation:YES];
+ [singleProgressBar startAnimation:self];
+
+ [metaString setString:@"\n"];
+
+ // grab the relations
+ CMMCPResult *theResult = [[mySQLConnection queryString:
+ [NSString stringWithFormat:@"SELECT CONCAT( table_name, ' -> ', referenced_table_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:@"%@ [ color=grey, arrowhead=crow, arrowtail=inv];\n", [[theResult fetchRowAsDictionary] objectForKey:@"list_of_fks"]]];
+ }
+
+ [theResult release];
+
+ // done
+ [metaString appendString:@"}\n"];
+
+ // Write information to the file
+ [fileHandle writeData:[metaString dataUsingEncoding:NSUTF8StringEncoding]];
+
+ // Restore the connection character set to pre-export details
+ [tableDocumentInstance
+ setConnectionEncoding:[NSString stringWithFormat:@"%@%@", previousConnectionEncoding, previousConnectionEncodingViaLatin1?@"-":@""]
+ reloadingViews:NO];
+
+
+ // Close the progress sheet
+ [NSApp endSheet:singleProgressSheet];
+ [singleProgressSheet orderOut:nil];
+
+
+ return TRUE;
+}
+
+
+/*
Takes an array and writes it in CSV format to the supplied NSFileHandle
*/
- (BOOL)writeCsvForArray:(NSArray *)array orQueryResult:(CMMCPResult *)queryResult toFileHandle:(NSFileHandle *)fileHandle