aboutsummaryrefslogtreecommitdiffstats
path: root/Source
diff options
context:
space:
mode:
Diffstat (limited to 'Source')
-rw-r--r--Source/CustomQuery.m4
-rw-r--r--Source/SPSQLParser.h5
-rw-r--r--Source/SPSQLParser.m47
-rw-r--r--Source/SPTableData.m8
-rw-r--r--Source/SPTableInfo.m14
-rw-r--r--Source/TableDocument.m60
-rw-r--r--Source/TablesList.h5
-rw-r--r--Source/TablesList.m279
8 files changed, 360 insertions, 62 deletions
diff --git a/Source/CustomQuery.m b/Source/CustomQuery.m
index 579f8c3e..a2cc0b9a 100644
--- a/Source/CustomQuery.m
+++ b/Source/CustomQuery.m
@@ -61,7 +61,7 @@
// Retrieve the custom query string and split it into separate SQL queries
queryParser = [[SPSQLParser alloc] initWithString:[textView string]];
- queries = [queryParser splitStringByCharacter:';'];
+ queries = [queryParser parseQueries];
[queryParser release];
NSRange curRange = [textView selectedRange];
@@ -110,7 +110,7 @@
// Otherwise, run the selected text.
} else {
queryParser = [[SPSQLParser alloc] initWithString:[[textView string] substringWithRange:selectedRange]];
- queries = [queryParser splitStringByCharacter:';'];
+ queries = [queryParser parseQueries];
[queryParser release];
}
diff --git a/Source/SPSQLParser.h b/Source/SPSQLParser.h
index 3e68501c..317e3e16 100644
--- a/Source/SPSQLParser.h
+++ b/Source/SPSQLParser.h
@@ -227,7 +227,10 @@ typedef enum _SPCommentTypes {
- (void) deleteCharactersInRange:(NSRange)aRange;
- (void) insertString:(NSString *)aString atIndex:(NSUInteger)anIndex;
-
+/*
+ * return an array of queries
+ */
+- (NSArray *) parseQueries;
/* Required and primitive methods to allow subclassing class cluster */
#pragma mark -
diff --git a/Source/SPSQLParser.m b/Source/SPSQLParser.m
index e5c490da..ad3697d6 100644
--- a/Source/SPSQLParser.m
+++ b/Source/SPSQLParser.m
@@ -30,6 +30,53 @@
@implementation SPSQLParser : NSMutableString
+/*
+ * return an array of queries
+ */
+- (NSArray *) parseQueries
+{
+ [self deleteComments];
+
+ /* this is a hack so I could test the funcs and procs viewing, needed a way to get those in.
+ * all this does is look for 'delimiter' in the text to trigger this parser. basically
+ * it runs through the query, line by line, and sets the delimiter accordingly to break
+ * out the individual queries. this is not very rebust but works for testing purposes.
+ * I believe Hans is currently working on a more robust parser. :mtv
+ */
+ if( [string rangeOfString:@"delimiter" options:NSCaseInsensitiveSearch].location != NSNotFound ) {
+ NSString *delim = @";";
+ NSString *thisLine = @"";
+ NSMutableArray *nq = [[NSMutableArray alloc] init];
+ NSArray *lines = [self splitStringByCharacter:'\n'];
+ for( NSString *line in lines ) {
+ line = [line stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
+ if( [line hasPrefix:@"delimiter"] ) {
+ delim = [line substringFromIndex:9];
+ delim = [delim stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
+ NSLog( @"delimiter now [%@]", delim );
+ continue;
+ }
+ if( [line hasSuffix:delim] ) {
+ thisLine = [thisLine stringByAppendingString:line];
+ [nq addObject:[thisLine substringWithRange:NSMakeRange(0,[thisLine length]-[delim length])]];
+ NSLog( @"query: [%@]", [thisLine substringWithRange:NSMakeRange(0,[thisLine length]-[delim length])] );
+ thisLine = @"";
+ }
+ else {
+ thisLine = [thisLine stringByAppendingString:line];
+ thisLine = [thisLine stringByAppendingString:@"\n"];
+ }
+ }
+ if( thisLine != @"" ) {
+ [nq addObject:thisLine];
+ NSLog( @"query: [%@]", thisLine );
+ }
+ return nq;
+ } else {
+ // just split as normal
+ return [self splitStringByCharacter:';'];
+ }
+}
/*
* Removes comments within the current string, trimming "#", "--[/s]", and "/* * /" style strings.
diff --git a/Source/SPTableData.m b/Source/SPTableData.m
index b791563b..4ed5823a 100644
--- a/Source/SPTableData.m
+++ b/Source/SPTableData.m
@@ -214,11 +214,15 @@
*/
- (BOOL) updateInformationForCurrentTable
{
- NSDictionary *tableData = [self informationForTable:[tableListInstance tableName]];
+ NSDictionary *tableData = nil;
NSDictionary *columnData;
NSEnumerator *enumerator;
- if (tableData == nil) {
+ if( [tableListInstance tableType] == SP_TABLETYPE_TABLE || [tableListInstance tableType] == SP_TABLETYPE_VIEW ) {
+ tableData = [self informationForTable:[tableListInstance tableName]];
+ }
+
+ if (tableData == nil ) {
[columns removeAllObjects];
[columnNames removeAllObjects];
return FALSE;
diff --git a/Source/SPTableInfo.m b/Source/SPTableInfo.m
index c87a337d..de933515 100644
--- a/Source/SPTableInfo.m
+++ b/Source/SPTableInfo.m
@@ -82,6 +82,20 @@
return;
}
+ if ([tableListInstance tableType] == SP_TABLETYPE_PROC) {
+ [info addObject:@"PROCEDURE INFORMATION"];
+ [info addObject:@"no information available"];
+ [infoTable reloadData];
+ return;
+ }
+
+ if ([tableListInstance tableType] == SP_TABLETYPE_FUNC) {
+ [info addObject:@"FUNCTION INFORMATION"];
+ [info addObject:@"no information available"];
+ [infoTable reloadData];
+ return;
+ }
+
[info addObject:@"TABLE INFORMATION"];
if ([tableListInstance tableName]) {
diff --git a/Source/TableDocument.m b/Source/TableDocument.m
index fcb3340e..6a769996 100644
--- a/Source/TableDocument.m
+++ b/Source/TableDocument.m
@@ -917,7 +917,32 @@ NSString *TableDocumentFavoritesControllerSelectionIndexDidChange = @"TableDocum
- (IBAction)showCreateTableSyntax:(id)sender
{
//Create the query and get results
- NSString *query = [NSString stringWithFormat:@"SHOW CREATE TABLE %@", [[self table] backtickQuotedString]];
+ NSString *query = nil;
+ NSString *createWindowTitle;
+ int colOffs = 1;
+
+ if( [tablesListInstance tableType] == SP_TABLETYPE_TABLE ) {
+ query = [NSString stringWithFormat:@"SHOW CREATE TABLE %@", [[self table] backtickQuotedString]];
+ createWindowTitle = @"Create Table Syntax";
+ }
+ else if( [tablesListInstance tableType] == SP_TABLETYPE_VIEW ) {
+ query = [NSString stringWithFormat:@"SHOW CREATE VIEW %@", [[self table] backtickQuotedString]];
+ createWindowTitle = @"Create View Syntax";
+ }
+ else if( [tablesListInstance tableType] == SP_TABLETYPE_PROC ) {
+ query = [NSString stringWithFormat:@"SHOW CREATE PROCEDURE %@", [[self table] backtickQuotedString]];
+ createWindowTitle = @"Create Procedure Syntax";
+ colOffs = 2;
+ }
+ else if( [tablesListInstance tableType] == SP_TABLETYPE_FUNC ) {
+ query = [NSString stringWithFormat:@"SHOW CREATE FUNCTION %@", [[self table] backtickQuotedString]];
+ createWindowTitle = @"Create Function Syntax";
+ colOffs = 2;
+ }
+
+ if( query == nil )
+ return;
+
CMMCPResult *theResult = [mySQLConnection queryString:query];
// Check for errors, only displaying if the connection hasn't been terminated
@@ -928,7 +953,7 @@ NSString *TableDocumentFavoritesControllerSelectionIndexDidChange = @"TableDocum
return;
}
- id tableSyntax = [[theResult fetchRowAsArray] objectAtIndex:1];
+ id tableSyntax = [[theResult fetchRowAsArray] objectAtIndex:colOffs];
if ([tableSyntax isKindOfClass:[NSData class]])
tableSyntax = [[NSString alloc] initWithData:tableSyntax encoding:[mySQLConnection encoding]];
@@ -938,6 +963,7 @@ NSString *TableDocumentFavoritesControllerSelectionIndexDidChange = @"TableDocum
else
[syntaxViewContent setString:tableSyntax];
+ [createTableSyntaxWindow setTitle:createWindowTitle];
[createTableSyntaxWindow makeKeyAndOrderFront:self];
}
@@ -946,8 +972,28 @@ NSString *TableDocumentFavoritesControllerSelectionIndexDidChange = @"TableDocum
*/
- (IBAction)copyCreateTableSyntax:(id)sender
{
- // Create the query and get results
- NSString *query = [NSString stringWithFormat:@"SHOW CREATE TABLE %@", [[self table] backtickQuotedString]];
+ // Create the query and get results
+ NSString *query = nil;
+ int colOffs = 1;
+
+ if( [tablesListInstance tableType] == SP_TABLETYPE_TABLE ) {
+ query = [NSString stringWithFormat:@"SHOW CREATE TABLE %@", [[self table] backtickQuotedString]];
+ }
+ else if( [tablesListInstance tableType] == SP_TABLETYPE_VIEW ) {
+ query = [NSString stringWithFormat:@"SHOW CREATE VIEW %@", [[self table] backtickQuotedString]];
+ }
+ else if( [tablesListInstance tableType] == SP_TABLETYPE_PROC ) {
+ query = [NSString stringWithFormat:@"SHOW CREATE PROCEDURE %@", [[self table] backtickQuotedString]];
+ colOffs = 2;
+ }
+ else if( [tablesListInstance tableType] == SP_TABLETYPE_FUNC ) {
+ query = [NSString stringWithFormat:@"SHOW CREATE FUNCTION %@", [[self table] backtickQuotedString]];
+ colOffs = 2;
+ }
+
+ if( query == nil )
+ return;
+
CMMCPResult *theResult = [mySQLConnection queryString:query];
// Check for errors, only displaying if the connection hasn't been terminated
@@ -958,7 +1004,7 @@ NSString *TableDocumentFavoritesControllerSelectionIndexDidChange = @"TableDocum
return;
}
- id tableSyntax = [[theResult fetchRowAsArray] objectAtIndex:1];
+ id tableSyntax = [[theResult fetchRowAsArray] objectAtIndex:colOffs];
if ([tableSyntax isKindOfClass:[NSData class]])
tableSyntax = [[NSString alloc] initWithData:tableSyntax encoding:[mySQLConnection encoding]];
@@ -972,9 +1018,9 @@ NSString *TableDocumentFavoritesControllerSelectionIndexDidChange = @"TableDocum
[pb setString:tableSyntax forType:NSStringPboardType];
// Table syntax copied Growl notification
- [[SPGrowlController sharedGrowlController] notifyWithTitle:@"Table Syntax Copied"
+ [[SPGrowlController sharedGrowlController] notifyWithTitle:@"Syntax Copied"
description:[NSString stringWithFormat:NSLocalizedString(@"Syntax for %@ table copied",@"description for table syntax copied growl notification"), [self table]]
- notificationName:@"Table Syntax Copied"];
+ notificationName:@"Syntax Copied"];
}
- (IBAction)copyColumnNames:(id)sender
diff --git a/Source/TablesList.h b/Source/TablesList.h
index 265fb73b..9eb632ab 100644
--- a/Source/TablesList.h
+++ b/Source/TablesList.h
@@ -27,8 +27,11 @@
enum sp_table_types
{
+ SP_TABLETYPE_NONE = -1,
SP_TABLETYPE_TABLE = 0,
- SP_TABLETYPE_VIEW = 1
+ SP_TABLETYPE_VIEW = 1,
+ SP_TABLETYPE_PROC = 2,
+ SP_TABLETYPE_FUNC = 3
};
@class CMMCResult, CMMCPConnection;
diff --git a/Source/TablesList.m b/Source/TablesList.m
index beeef5a1..14a3711f 100644
--- a/Source/TablesList.m
+++ b/Source/TablesList.m
@@ -57,7 +57,7 @@
[tablesListView deselectAll:self];
[tables removeAllObjects];
[tableTypes removeAllObjects];
- [tableTypes addObject:[NSNumber numberWithInt:-1]];
+ [tableTypes addObject:[NSNumber numberWithInt:SP_TABLETYPE_NONE]];
if ([tableDocumentInstance database]) {
@@ -85,6 +85,96 @@
}
}
}
+
+ /* grab the procedures and functions
+ *
+ * using information_schema gives us more info (for information window perhaps?) but breaks
+ * backward compatibility with pre 4 I believe. I left the other methods below, in case.
+ */
+ NSString *pQuery = [NSString stringWithFormat:@"SELECT * FROM information_schema.routines WHERE routine_schema = '%@' ORDER BY routine_name",[tableDocumentInstance database]];
+ theResult = [mySQLConnection queryString:pQuery];
+
+ if( [theResult numOfRows] ) {
+ // add the header row
+ [tables addObject:NSLocalizedString(@"PROCS & FUNCS",@"header for procs & funcs list")];
+ [tableTypes addObject:[NSNumber numberWithInt:SP_TABLETYPE_NONE]];
+ [theResult dataSeek:0];
+
+ if( [theResult numOfFields] == 1 ) {
+ for( i = 0; i < [theResult numOfRows]; i++ ) {
+ [tables addObject:[[theResult fetchRowAsArray] objectAtIndex:3]];
+ if( [[[theResult fetchRowAsArray] objectAtIndex:4] isEqualToString:@"PROCEDURE"]) {
+ [tableTypes addObject:[NSNumber numberWithInt:SP_TABLETYPE_PROC]];
+ } else {
+ [tableTypes addObject:[NSNumber numberWithInt:SP_TABLETYPE_FUNC]];
+ }
+ }
+ } else {
+ for( i = 0; i < [theResult numOfRows]; i++ ) {
+ resultRow = [theResult fetchRowAsArray];
+ [tables addObject:[resultRow objectAtIndex:3]];
+ if( [[resultRow objectAtIndex:4] isEqualToString:@"PROCEDURE"] ) {
+ [tableTypes addObject:[NSNumber numberWithInt:SP_TABLETYPE_PROC]];
+ } else {
+ [tableTypes addObject:[NSNumber numberWithInt:SP_TABLETYPE_FUNC]];
+ }
+ }
+ }
+ }
+
+ /*
+ BOOL addedPFHeader = FALSE;
+ NSString *pQuery = [NSString stringWithFormat:@"SHOW PROCEDURE STATUS WHERE db = '%@'",[tableDocumentInstance database]];
+ theResult = [mySQLConnection queryString:pQuery];
+
+ if( [theResult numOfRows] ) {
+ // add the header row
+ [tables addObject:NSLocalizedString(@"PROCS & FUNCS",@"header for procs & funcs list")];
+ [tableTypes addObject:[NSNumber numberWithInt:SP_TABLETYPE_NONE]];
+ addedPFHeader = TRUE;
+ [theResult dataSeek:0];
+
+ if( [theResult numOfFields] == 1 ) {
+ for( i = 0; i < [theResult numOfRows]; i++ ) {
+ [tables addObject:[[theResult fetchRowAsArray] objectAtIndex:1]];
+ [tableTypes addObject:[NSNumber numberWithInt:SP_TABLETYPE_PROC]];
+ }
+ } else {
+ for( i = 0; i < [theResult numOfRows]; i++ ) {
+ resultRow = [theResult fetchRowAsArray];
+ [tables addObject:[resultRow objectAtIndex:1]];
+ [tableTypes addObject:[NSNumber numberWithInt:SP_TABLETYPE_PROC]];
+ }
+ }
+ }
+
+ pQuery = [NSString stringWithFormat:@"SHOW FUNCTION STATUS WHERE db = '%@'",[tableDocumentInstance database]];
+ theResult = [mySQLConnection queryString:pQuery];
+
+ if( [theResult numOfRows] ) {
+ if( !addedPFHeader ) {
+ // add the header row
+ [tables addObject:NSLocalizedString(@"PROCS & FUNCS",@"header for procs & funcs list")];
+ [tableTypes addObject:[NSNumber numberWithInt:SP_TABLETYPE_NONE]];
+ }
+ [theResult dataSeek:0];
+
+ if( [theResult numOfFields] == 1 ) {
+ for( i = 0; i < [theResult numOfRows]; i++ ) {
+ [tables addObject:[[theResult fetchRowAsArray] objectAtIndex:1]];
+ [tableTypes addObject:[NSNumber numberWithInt:SP_TABLETYPE_FUNC]];
+ }
+ } else {
+ for( i = 0; i < [theResult numOfRows]; i++ ) {
+ resultRow = [theResult fetchRowAsArray];
+ [tables addObject:[resultRow objectAtIndex:1]];
+ [tableTypes addObject:[NSNumber numberWithInt:SP_TABLETYPE_FUNC]];
+ }
+ }
+ }
+ */
+ // Notify listeners that the query has finished
+ [[NSNotificationCenter defaultCenter] postNotificationName:@"SMySQLQueryHasBeenPerformed" object:self];
}
if (containsViews) {
@@ -93,9 +183,6 @@
[tables insertObject:NSLocalizedString(@"TABLES",@"header for table list") atIndex:0];
}
- // Notify listeners that the query has finished
- [[NSNotificationCenter defaultCenter] postNotificationName:@"SMySQLQueryHasBeenPerformed" object:self];
-
[tablesListView reloadData];
//if the previous selected table still exists, select it
@@ -145,12 +232,11 @@
[mySQLConnection queryString:createStatement];
if ([[mySQLConnection getLastErrorMessage] isEqualToString:@""]) {
-
// Table creation was successful
- [tables addObject:tableName];
- [tableTypes addObject:[NSNumber numberWithInt:SP_TABLETYPE_TABLE]];
+ [tables insertObject:tableName atIndex:1];
+ [tableTypes insertObject:[NSNumber numberWithInt:SP_TABLETYPE_TABLE] atIndex:1];
[tablesListView reloadData];
- [tablesListView selectRow:([tables count] - 1) byExtendingSelection:NO];
+ [tablesListView selectRow:1 byExtendingSelection:NO];
NSInteger selectedIndex = [tabView indexOfTabViewItem:[tabView selectedTabViewItem]];
@@ -229,8 +315,13 @@
if ([tablesListView numberOfSelectedRows] == 1) {
if([[tableTypes objectAtIndex:currentIndex] intValue] == SP_TABLETYPE_VIEW)
tblTypes = NSLocalizedString(@"view", @"view");
- else
+ else if([[tableTypes objectAtIndex:currentIndex] intValue] == SP_TABLETYPE_TABLE)
tblTypes = NSLocalizedString(@"table", @"table");
+ else if([[tableTypes objectAtIndex:currentIndex] intValue] == SP_TABLETYPE_PROC)
+ tblTypes = NSLocalizedString(@"procedure", @"procedure");
+ else if([[tableTypes objectAtIndex:currentIndex] intValue] == SP_TABLETYPE_FUNC)
+ tblTypes = NSLocalizedString(@"function", @"function");
+
[alert setMessageText:[NSString stringWithFormat:NSLocalizedString(@"Delete %@ '%@'?", @"delete table/view message"), tblTypes, [tables objectAtIndex:[tablesListView selectedRow]]]];
[alert setInformativeText:[NSString stringWithFormat:NSLocalizedString(@"Are you sure you want to delete the %@ '%@'. This operation cannot be undone.", @"delete table/view informative message"), tblTypes, [tables objectAtIndex:[tablesListView selectedRow]]]];
}
@@ -272,8 +363,14 @@
// int rowCount, i, j;
// BOOL errors = NO;
- if ( [tablesListView numberOfSelectedRows] != 1 )
+ if ( [tablesListView numberOfSelectedRows] != 1 ||
+ [[tableTypes objectAtIndex:[tablesListView selectedRow]] intValue] == SP_TABLETYPE_PROC ||
+ [[tableTypes objectAtIndex:[tablesListView selectedRow]] intValue] == SP_TABLETYPE_FUNC ) {
+
return;
+ }
+
+
if ( ![tableSourceInstance saveRowOnDeselect] || ![tableContentInstance saveRowOnDeselect] ) {
return;
}
@@ -429,11 +526,20 @@
[mySQLConnection queryString: [NSString stringWithFormat: @"DROP VIEW %@",
[[tables objectAtIndex:currentIndex] backtickQuotedString]
]];
- } else {
+ } else if([[tableTypes objectAtIndex:currentIndex] intValue] == SP_TABLETYPE_TABLE) {
[mySQLConnection queryString: [NSString stringWithFormat: @"DROP TABLE %@",
- [[tables objectAtIndex:currentIndex] backtickQuotedString]
- ]];
- }
+ [[tables objectAtIndex:currentIndex] backtickQuotedString]
+ ]];
+ } else if([[tableTypes objectAtIndex:currentIndex] intValue] == SP_TABLETYPE_PROC) {
+ [mySQLConnection queryString: [NSString stringWithFormat: @"DROP PROCEDURE %@",
+ [[tables objectAtIndex:currentIndex] backtickQuotedString]
+ ]];
+ } else if([[tableTypes objectAtIndex:currentIndex] intValue] == SP_TABLETYPE_FUNC) {
+ [mySQLConnection queryString: [NSString stringWithFormat: @"DROP FUNCTION %@",
+ [[tables objectAtIndex:currentIndex] backtickQuotedString]
+ ]];
+ }
+
if ( [[mySQLConnection getLastErrorMessage] isEqualTo:@""] ) {
//dropped table with success
[tables removeObjectAtIndex:currentIndex];
@@ -712,36 +818,47 @@
// Reset the table information caches
[tableDataInstance resetAllData];
- // If encoding is set to Autodetect, update the connection character set encoding
- // based on the newly selected table's encoding - but only if it differs from the current encoding.
- if ([[[NSUserDefaults standardUserDefaults] objectForKey:@"DefaultEncoding"] isEqualToString:@"Autodetect"]) {
- if (![[tableDataInstance tableEncoding] isEqualToString:[tableDocumentInstance connectionEncoding]]) {
- [tableDocumentInstance setConnectionEncoding:[tableDataInstance tableEncoding] reloadingViews:NO];
- [tableDataInstance resetAllData];
+ if( [[tableTypes objectAtIndex:[tablesListView selectedRow]] intValue] == SP_TABLETYPE_VIEW ||
+ [[tableTypes objectAtIndex:[tablesListView selectedRow]] intValue] == SP_TABLETYPE_TABLE) {
+ // If encoding is set to Autodetect, update the connection character set encoding
+ // based on the newly selected table's encoding - but only if it differs from the current encoding.
+ if ([[[NSUserDefaults standardUserDefaults] objectForKey:@"DefaultEncoding"] isEqualToString:@"Autodetect"]) {
+ if (![[tableDataInstance tableEncoding] isEqualToString:[tableDocumentInstance connectionEncoding]]) {
+ [tableDocumentInstance setConnectionEncoding:[tableDataInstance tableEncoding] reloadingViews:NO];
+ [tableDataInstance resetAllData];
+ }
+ }
+
+ if ( [tabView indexOfTabViewItem:[tabView selectedTabViewItem]] == 0 ) {
+ [tableSourceInstance loadTable:[tables objectAtIndex:[tablesListView selectedRow]]];
+ structureLoaded = YES;
+ contentLoaded = NO;
+ statusLoaded = NO;
+ } else if ( [tabView indexOfTabViewItem:[tabView selectedTabViewItem]] == 1 ) {
+ [tableContentInstance loadTable:[tables objectAtIndex:[tablesListView selectedRow]]];
+ structureLoaded = NO;
+ contentLoaded = YES;
+ statusLoaded = NO;
+ } else if ( [tabView indexOfTabViewItem:[tabView selectedTabViewItem]] == 3 ) {
+ [tableStatusInstance loadTable:[tables objectAtIndex:[tablesListView selectedRow]]];
+ structureLoaded = NO;
+ contentLoaded = NO;
+ statusLoaded = YES;
+ } else {
+ structureLoaded = NO;
+ contentLoaded = NO;
+ statusLoaded = NO;
}
- }
-
- if ( [tabView indexOfTabViewItem:[tabView selectedTabViewItem]] == 0 ) {
- [tableSourceInstance loadTable:[tables objectAtIndex:[tablesListView selectedRow]]];
- structureLoaded = YES;
- contentLoaded = NO;
- statusLoaded = NO;
- } else if ( [tabView indexOfTabViewItem:[tabView selectedTabViewItem]] == 1 ) {
- [tableContentInstance loadTable:[tables objectAtIndex:[tablesListView selectedRow]]];
- structureLoaded = NO;
- contentLoaded = YES;
- statusLoaded = NO;
- } else if ( [tabView indexOfTabViewItem:[tabView selectedTabViewItem]] == 3 ) {
- [tableStatusInstance loadTable:[tables objectAtIndex:[tablesListView selectedRow]]];
- structureLoaded = NO;
- contentLoaded = NO;
- statusLoaded = YES;
} else {
+ // if we are not looking at a table or view, clear these
+ [tableSourceInstance loadTable:nil];
+ [tableContentInstance loadTable:nil];
+ [tableStatusInstance loadTable:nil];
structureLoaded = NO;
contentLoaded = NO;
- statusLoaded = NO;
+ statusLoaded = NO;
}
-
+
// Set gear menu items Remove/Duplicate table/view and mainMenu > Table items
// according to the table types
if([[tableTypes objectAtIndex:[tablesListView selectedRow]] intValue] == SP_TABLETYPE_VIEW)
@@ -749,8 +866,12 @@
// Change mainMenu > Table > ... according to table type
[[[[[NSApp mainMenu] itemAtIndex:5] submenu] itemAtIndex:0] setTitle:NSLocalizedString(@"Copy Create View Syntax", @"copy create view syntax menu item")];
[[[[[NSApp mainMenu] itemAtIndex:5] submenu] itemAtIndex:1] setTitle:NSLocalizedString(@"Show Create View Syntax", @"show create view syntax menu item")];
+ [[[[[NSApp mainMenu] itemAtIndex:5] submenu] itemAtIndex:2] setHidden:NO]; // divider
+ [[[[[NSApp mainMenu] itemAtIndex:5] submenu] itemAtIndex:3] setHidden:NO]; // copy columns
+ [[[[[NSApp mainMenu] itemAtIndex:5] submenu] itemAtIndex:4] setHidden:NO]; // divider
[[[[[NSApp mainMenu] itemAtIndex:5] submenu] itemAtIndex:5] setTitle:NSLocalizedString(@"Check View", @"check view menu item")];
[[[[[NSApp mainMenu] itemAtIndex:5] submenu] itemAtIndex:6] setHidden:YES]; // repair
+ [[[[[NSApp mainMenu] itemAtIndex:5] submenu] itemAtIndex:7] setHidden:YES]; // divider
[[[[[NSApp mainMenu] itemAtIndex:5] submenu] itemAtIndex:8] setHidden:YES]; // analyse
[[[[[NSApp mainMenu] itemAtIndex:5] submenu] itemAtIndex:9] setHidden:YES]; // optimize
[[[[[NSApp mainMenu] itemAtIndex:5] submenu] itemAtIndex:10] setTitle:NSLocalizedString(@"Flush View", @"flush view menu item")];
@@ -758,11 +879,16 @@
[removeTableMenuItem setTitle:NSLocalizedString(@"Remove view", @"remove view menu title")];
[duplicateTableMenuItem setTitle:NSLocalizedString(@"Duplicate view", @"duplicate view menu title")];
- } else {
+ }
+ else if([[tableTypes objectAtIndex:[tablesListView selectedRow]] intValue] == SP_TABLETYPE_TABLE) {
[[[[[NSApp mainMenu] itemAtIndex:5] submenu] itemAtIndex:0] setTitle:NSLocalizedString(@"Copy Create Table Syntax", @"copy create table syntax menu item")];
[[[[[NSApp mainMenu] itemAtIndex:5] submenu] itemAtIndex:1] setTitle:NSLocalizedString(@"Show Create Table Syntax", @"show create table syntax menu item")];
+ [[[[[NSApp mainMenu] itemAtIndex:5] submenu] itemAtIndex:2] setHidden:NO]; // divider
+ [[[[[NSApp mainMenu] itemAtIndex:5] submenu] itemAtIndex:3] setHidden:NO]; // copy columns
+ [[[[[NSApp mainMenu] itemAtIndex:5] submenu] itemAtIndex:4] setHidden:NO]; // divider
[[[[[NSApp mainMenu] itemAtIndex:5] submenu] itemAtIndex:5] setTitle:NSLocalizedString(@"Check Table", @"check table menu item")];
[[[[[NSApp mainMenu] itemAtIndex:5] submenu] itemAtIndex:6] setHidden:NO];
+ [[[[[NSApp mainMenu] itemAtIndex:5] submenu] itemAtIndex:7] setHidden:NO]; // divider
[[[[[NSApp mainMenu] itemAtIndex:5] submenu] itemAtIndex:8] setHidden:NO];
[[[[[NSApp mainMenu] itemAtIndex:5] submenu] itemAtIndex:9] setHidden:NO];
[[[[[NSApp mainMenu] itemAtIndex:5] submenu] itemAtIndex:10] setTitle:NSLocalizedString(@"Flush Table", @"flush table menu item")];
@@ -770,8 +896,41 @@
[removeTableMenuItem setTitle:NSLocalizedString(@"Remove table", @"remove table menu title")];
[duplicateTableMenuItem setTitle:NSLocalizedString(@"Duplicate table", @"duplicate table menu title")];
+ }
+ else if([[tableTypes objectAtIndex:[tablesListView selectedRow]] intValue] == SP_TABLETYPE_PROC) {
+ [[[[[NSApp mainMenu] itemAtIndex:5] submenu] itemAtIndex:0] setTitle:NSLocalizedString(@"Copy Create Procedure Syntax", @"copy create proc syntax menu item")];
+ [[[[[NSApp mainMenu] itemAtIndex:5] submenu] itemAtIndex:1] setTitle:NSLocalizedString(@"Show Create Procedure Syntax", @"show create proc syntax menu item")];
+ [[[[[NSApp mainMenu] itemAtIndex:5] submenu] itemAtIndex:2] setHidden:YES]; // divider
+ [[[[[NSApp mainMenu] itemAtIndex:5] submenu] itemAtIndex:3] setHidden:YES]; // copy columns
+ [[[[[NSApp mainMenu] itemAtIndex:5] submenu] itemAtIndex:4] setHidden:YES]; // divider
+ [[[[[NSApp mainMenu] itemAtIndex:5] submenu] itemAtIndex:5] setHidden:YES];
+ [[[[[NSApp mainMenu] itemAtIndex:5] submenu] itemAtIndex:6] setHidden:YES];
+ [[[[[NSApp mainMenu] itemAtIndex:5] submenu] itemAtIndex:7] setHidden:YES]; // divider
+ [[[[[NSApp mainMenu] itemAtIndex:5] submenu] itemAtIndex:8] setHidden:YES];
+ [[[[[NSApp mainMenu] itemAtIndex:5] submenu] itemAtIndex:9] setHidden:YES];
+ [[[[[NSApp mainMenu] itemAtIndex:5] submenu] itemAtIndex:10] setHidden:YES];
+ [[[[[NSApp mainMenu] itemAtIndex:5] submenu] itemAtIndex:11] setHidden:YES];
+
+ [removeTableMenuItem setTitle:NSLocalizedString(@"Remove procedure", @"remove proc menu title")];
+ [duplicateTableMenuItem setTitle:NSLocalizedString(@"Duplicate procedure", @"duplicate proc menu title")];
+ }
+ else if([[tableTypes objectAtIndex:[tablesListView selectedRow]] intValue] == SP_TABLETYPE_FUNC) {
+ [[[[[NSApp mainMenu] itemAtIndex:5] submenu] itemAtIndex:0] setTitle:NSLocalizedString(@"Copy Create Function Syntax", @"copy create func syntax menu item")];
+ [[[[[NSApp mainMenu] itemAtIndex:5] submenu] itemAtIndex:1] setTitle:NSLocalizedString(@"Show Create Function Syntax", @"show create func syntax menu item")];
+ [[[[[NSApp mainMenu] itemAtIndex:5] submenu] itemAtIndex:2] setHidden:YES]; // divider
+ [[[[[NSApp mainMenu] itemAtIndex:5] submenu] itemAtIndex:3] setHidden:YES]; // copy columns
+ [[[[[NSApp mainMenu] itemAtIndex:5] submenu] itemAtIndex:4] setHidden:YES]; // divider
+ [[[[[NSApp mainMenu] itemAtIndex:5] submenu] itemAtIndex:5] setHidden:YES];
+ [[[[[NSApp mainMenu] itemAtIndex:5] submenu] itemAtIndex:6] setHidden:YES];
+ [[[[[NSApp mainMenu] itemAtIndex:5] submenu] itemAtIndex:7] setHidden:YES]; // divider
+ [[[[[NSApp mainMenu] itemAtIndex:5] submenu] itemAtIndex:8] setHidden:YES];
+ [[[[[NSApp mainMenu] itemAtIndex:5] submenu] itemAtIndex:9] setHidden:YES];
+ [[[[[NSApp mainMenu] itemAtIndex:5] submenu] itemAtIndex:10] setHidden:YES];
+ [[[[[NSApp mainMenu] itemAtIndex:5] submenu] itemAtIndex:11] setHidden:YES];
+
+ [removeTableMenuItem setTitle:NSLocalizedString(@"Remove function", @"remove func menu title")];
+ [duplicateTableMenuItem setTitle:NSLocalizedString(@"Duplicate function", @"duplicate func menu title")];
}
-
// set window title
[tableWindow setTitle:[NSString stringWithFormat:@"(MySQL %@) %@/%@/%@", [tableDocumentInstance mySQLVersion],
[tableDocumentInstance name], [tableDocumentInstance database], [tables objectAtIndex:[tablesListView selectedRow]]]];
@@ -810,15 +969,21 @@
*/
- (BOOL)tableView:(NSTableView *)aTableView shouldSelectRow:(int)rowIndex
{
- return (rowIndex != 0);
+ //return (rowIndex != 0);
+ if( [tableTypes count] == 0 )
+ return (rowIndex != 0 );
+ return ([[tableTypes objectAtIndex:rowIndex] intValue] != SP_TABLETYPE_NONE );
}
/**
* Table view delegate method
*/
-- (BOOL)tableView:(NSTableView *)aTableView isGroupRow:(int)row
+- (BOOL)tableView:(NSTableView *)aTableView isGroupRow:(int)rowIndex
{
- return (row == 0);
+ //return (row == 0);
+ if( [tableTypes count] == 0 )
+ return (rowIndex == 0 );
+ return ([[tableTypes objectAtIndex:rowIndex] intValue] == SP_TABLETYPE_NONE );
}
/**
@@ -829,12 +994,21 @@
if (rowIndex > 0 && [[aTableColumn identifier] isEqualToString:@"tables"]) {
if ([[tableTypes objectAtIndex:rowIndex] intValue] == SP_TABLETYPE_VIEW) {
[(ImageAndTextCell*)aCell setImage:[NSImage imageNamed:@"table-view-small"]];
- } else {
+ } else if ([[tableTypes objectAtIndex:rowIndex] intValue] == SP_TABLETYPE_TABLE) {
[(ImageAndTextCell*)aCell setImage:[NSImage imageNamed:@"table-small"]];
+ } else if ([[tableTypes objectAtIndex:rowIndex] intValue] == SP_TABLETYPE_PROC) {
+ [(ImageAndTextCell*)aCell setImage:[NSImage imageNamed:@"proc-small"]];
+ } else if ([[tableTypes objectAtIndex:rowIndex] intValue] == SP_TABLETYPE_FUNC) {
+ [(ImageAndTextCell*)aCell setImage:[NSImage imageNamed:@"func-small"]];
+ }
+
+ if ([[tableTypes objectAtIndex:rowIndex] intValue] == SP_TABLETYPE_NONE) {
+ [(ImageAndTextCell*)aCell setImage:nil];
+ [(ImageAndTextCell*)aCell setIndentationLevel:0];
+ } else {
+ [(ImageAndTextCell*)aCell setIndentationLevel:1];
+ [(ImageAndTextCell*)aCell setFont:[NSFont systemFontOfSize:[NSFont smallSystemFontSize]]];
}
-
- [(ImageAndTextCell*)aCell setIndentationLevel:1];
- [(ImageAndTextCell*)aCell setFont:[NSFont systemFontOfSize:[NSFont smallSystemFontSize]]];
} else {
[(ImageAndTextCell*)aCell setImage:nil];
[(ImageAndTextCell*)aCell setIndentationLevel:0];
@@ -856,7 +1030,8 @@
*/
- (void)tabView:(NSTabView *)aTabView didSelectTabViewItem:(NSTabViewItem *)tabViewItem
{
- if ( [tablesListView numberOfSelectedRows] == 1 ) {
+ if ( [tablesListView numberOfSelectedRows] == 1 &&
+ ([tablesListView tableType] == SP_TABLETYPE_TABLE || [tablesListView tableType] == SP_TABLETYPE_VIEW) ) {
if ( ([tabView indexOfTabViewItem:[tabView selectedTabViewItem]] == 0) && !structureLoaded ) {
[tableSourceInstance loadTable:[tables objectAtIndex:[tablesListView selectedRow]]];
@@ -873,6 +1048,10 @@
statusLoaded = YES;
}
}
+ else {
+ [tableSourceInstance loadTable:nil];
+ [tableContentInstance loadTable:nil];
+ }
}
/**
@@ -883,6 +1062,8 @@
// popup button below table list
if ([menuItem action] == @selector(copyTable:))
{
+ if( [self tableType] == SP_TABLETYPE_FUNC || [self tableType] == SP_TABLETYPE_PROC )
+ return NO;
return [tablesListView numberOfSelectedRows] == 1 && [[self tableName] length] && [tablesListView numberOfSelectedRows] > 0;
}
if ([menuItem action] == @selector(removeTable:))