aboutsummaryrefslogtreecommitdiffstats
path: root/Source/TableSource.m
diff options
context:
space:
mode:
authorstuconnolly <stuart02@gmail.com>2010-03-12 01:02:52 +0000
committerstuconnolly <stuart02@gmail.com>2010-03-12 01:02:52 +0000
commit88f89987a4329b394ee30a2a77705d3afbb35195 (patch)
tree71d53571320669deb0881485fd53dc5062c7ae3f /Source/TableSource.m
parent98af234687c698826817a6c219ce8f731fdfa1e7 (diff)
downloadsequelpro-88f89987a4329b394ee30a2a77705d3afbb35195.tar.gz
sequelpro-88f89987a4329b394ee30a2a77705d3afbb35195.tar.bz2
sequelpro-88f89987a4329b394ee30a2a77705d3afbb35195.zip
Various printing support enhancements, including:
- Splitting out all printing methods to SPPrintController which is category of TableDocument. - The ability to print table relations. - If present the inclusion of table indexes when printing a table's source. - If the user has use monospaced fonts enables, then the print out's tabular data will be in a monospaced font. - Lots of other style enhancements, including page headings and sections headings.
Diffstat (limited to 'Source/TableSource.m')
-rw-r--r--Source/TableSource.m56
1 files changed, 41 insertions, 15 deletions
diff --git a/Source/TableSource.m b/Source/TableSource.m
index ed624445..05eb0c53 100644
--- a/Source/TableSource.m
+++ b/Source/TableSource.m
@@ -1115,22 +1115,50 @@ returns a dictionary containing enum/set field names as key and possible values
return [NSDictionary dictionaryWithDictionary:enumFields];
}
-- (NSArray *)tableStructureForPrint
-{
- MCPResult *queryResult;
- NSMutableArray *tempResult = [NSMutableArray array];
+/**
+ * Returns a dictionary describing the source of the table to be used for printing purposes. The object accessible
+ * via the key 'structure' is an array of the tables fields, where the first element is always the field names
+ * and each subsequent element is the field data. This is also true for the table's indexes, which are accessible
+ * via the key 'indexes'.
+ */
+- (NSDictionary *)tableSourceForPrinting
+{
NSInteger i;
+ NSMutableArray *tempResult = [NSMutableArray array];
+ NSMutableArray *tempResult2 = [NSMutableArray array];
+
+ MCPResult *structureQueryResult = [mySQLConnection queryString:[NSString stringWithFormat:@"SHOW COLUMNS FROM %@", [selectedTable backtickQuotedString]]];
+ MCPResult *indexesQueryResult = [mySQLConnection queryString:[NSString stringWithFormat:@"SHOW INDEXES FROM %@", [selectedTable backtickQuotedString]]];
+
+ [structureQueryResult setReturnDataAsStrings:YES];
+ [indexesQueryResult setReturnDataAsStrings:YES];
+
+ if ([structureQueryResult numOfRows]) [structureQueryResult dataSeek:0];
+ if ([indexesQueryResult numOfRows]) [indexesQueryResult dataSeek:0];
+
+ [tempResult addObject:[structureQueryResult fetchFieldNames]];
+
+ NSMutableArray *temp = [[[indexesQueryResult fetchFieldNames] mutableCopy] autorelease];
- queryResult = [mySQLConnection queryString:[NSString stringWithFormat:@"SHOW COLUMNS FROM %@", [selectedTable backtickQuotedString]]];
- [queryResult setReturnDataAsStrings:YES];
+ // Remove the 'table' column
+ [temp removeObjectAtIndex:0];
- if ([queryResult numOfRows]) [queryResult dataSeek:0];
- [tempResult addObject:[queryResult fetchFieldNames]];
- for ( i = 0 ; i < [queryResult numOfRows] ; i++ ) {
- [tempResult addObject:[queryResult fetchRowAsArray]];
+ [tempResult2 addObject:temp];
+
+ for (i = 0 ; i < [structureQueryResult numOfRows]; i++) {
+ [tempResult addObject:[structureQueryResult fetchRowAsArray]];
}
- return tempResult;
+ for (i = 0 ; i < [indexesQueryResult numOfRows]; i++) {
+ NSMutableArray *index = [[[indexesQueryResult fetchRowAsArray] mutableCopy] autorelease];
+
+ // Remove the 'table' column values
+ [index removeObjectAtIndex:0];
+
+ [tempResult2 addObject:index];
+ }
+
+ return [NSDictionary dictionaryWithObjectsAndKeys:tempResult, @"structure", tempResult2, @"indexes", nil];
}
#pragma mark -
@@ -1143,8 +1171,7 @@ returns a dictionary containing enum/set field names as key and possible values
{
// Only proceed if this view is selected.
- if (![[tableDocumentInstance selectedToolbarItemIdentifier] isEqualToString:SPMainToolbarTableStructure])
- return;
+ if (![[tableDocumentInstance selectedToolbarItemIdentifier] isEqualToString:SPMainToolbarTableStructure]) return;
[tableSourceView setEnabled:NO];
[addFieldButton setEnabled:NO];
@@ -1166,8 +1193,7 @@ returns a dictionary containing enum/set field names as key and possible values
{
// Only re-enable elements if the current tab is the structure view
- if (![[tableDocumentInstance selectedToolbarItemIdentifier] isEqualToString:SPMainToolbarTableStructure])
- return;
+ if (![[tableDocumentInstance selectedToolbarItemIdentifier] isEqualToString:SPMainToolbarTableStructure]) return;
BOOL editingEnabled = ([tablesListInstance tableType] == SP_TABLETYPE_TABLE);
[tableSourceView setEnabled:YES];