diff options
-rw-r--r-- | Source/CMTextView.m | 104 | ||||
-rw-r--r-- | Source/TableDocument.h | 3 | ||||
-rw-r--r-- | Source/TableDocument.m | 32 | ||||
-rw-r--r-- | Source/TablesList.h | 6 | ||||
-rw-r--r-- | Source/TablesList.m | 72 |
5 files changed, 131 insertions, 86 deletions
diff --git a/Source/CMTextView.m b/Source/CMTextView.m index 3f9a0d57..c99baa1a 100644 --- a/Source/CMTextView.m +++ b/Source/CMTextView.m @@ -129,60 +129,36 @@ NSInteger alphabeticSort(id string1, id string2, void *reverse) NSMutableArray *compl = [[NSMutableArray alloc] initWithCapacity:32]; NSMutableArray *possibleCompletions = [[NSMutableArray alloc] initWithCapacity:32]; - unsigned i; if([mySQLConnection isConnected] && !isDictMode) { // Add table names to completions list - MCPResult *queryResult = [mySQLConnection listTables]; - if ([queryResult numOfRows]) - [queryResult dataSeek:0]; - for (i = 0 ; i < [queryResult numOfRows] ; i++) - { - [possibleCompletions addObject:[NSDictionary dictionaryWithObjectsAndKeys:NSArrayObjectAtIndex([queryResult fetchRowAsArray], 0), @"display", @"table-small-square", @"image", nil]]; - //[possibleCompletions addObject:[[queryResult fetchRowAsArray] objectAtIndex:0]]; - } + for (id obj in [[[[self window] delegate] valueForKeyPath:@"tablesListInstance"] valueForKey:@"allTableAndViewNames"]) + [possibleCompletions addObject:[NSDictionary dictionaryWithObjectsAndKeys:obj, @"display", @"table-small-square", @"image", nil]]; + + // Add view names to completions list + // for (id obj in [[[[self window] delegate] valueForKeyPath:@"tablesListInstance"] valueForKey:@"allViewNames"]) + // [possibleCompletions addObject:[NSDictionary dictionaryWithObjectsAndKeys:obj, @"display", @"table-view-small", @"image", nil]]; // Add field names to completions list for currently selected table - if ([[[self window] delegate] table] != nil) { - id columnNames = [[[[self window] delegate] valueForKeyPath:@"tableDataInstance"] valueForKey:@"columnNames"]; - // [possibleCompletions addObjectsFromArray:columnNames]; - NSString *s; - enumerate(columnNames, s) - [possibleCompletions addObject:[NSDictionary dictionaryWithObjectsAndKeys:s, @"display", @"dummy-small", @"image", nil]]; - } + if ([[[self window] delegate] table] != nil) + for (id obj in [[[[self window] delegate] valueForKeyPath:@"tableDataInstance"] valueForKey:@"columnNames"]) + [possibleCompletions addObject:[NSDictionary dictionaryWithObjectsAndKeys:obj, @"display", @"dummy-small", @"image", nil]]; + // Add all database names to completions list - queryResult = [mySQLConnection listDBs]; - if ([queryResult numOfRows]) - [queryResult dataSeek:0]; - for (i = 0 ; i < [queryResult numOfRows] ; i++) - { - // [possibleCompletions addObject:[[queryResult fetchRowAsArray] objectAtIndex:0]]; - [possibleCompletions addObject:[NSDictionary dictionaryWithObjectsAndKeys:NSArrayObjectAtIndex([queryResult fetchRowAsArray], 0), @"display", @"database-small", @"image", nil]]; - } + for (id obj in [[[[self window] delegate] valueForKeyPath:@"tablesListInstance"] valueForKey:@"allDatabaseNames"]) + [possibleCompletions addObject:[NSDictionary dictionaryWithObjectsAndKeys:obj, @"display", @"database-small", @"image", nil]]; // Add proc/func only for MySQL version 5 or higher if(mySQLmajorVersion > 4) { // Add all procedures to completions list for currently selected table - queryResult = [mySQLConnection queryString:@"SHOW PROCEDURE STATUS"]; - if ([queryResult numOfRows]) - [queryResult dataSeek:0]; - for (i = 0 ; i < [queryResult numOfRows] ; i++) - { - // [possibleCompletions addObject:[[queryResult fetchRowAsArray] objectAtIndex:1]]; - [possibleCompletions addObject:[NSDictionary dictionaryWithObjectsAndKeys:NSArrayObjectAtIndex([queryResult fetchRowAsArray], 1), @"display", @"proc-small", @"image", nil]]; - } + for (id obj in [[[[self window] delegate] valueForKeyPath:@"tablesListInstance"] valueForKey:@"allProcedureNames"]) + [possibleCompletions addObject:[NSDictionary dictionaryWithObjectsAndKeys:obj, @"display", @"proc-small", @"image", nil]]; // Add all function to completions list for currently selected table - queryResult = [mySQLConnection queryString:@"SHOW FUNCTION STATUS"]; - if ([queryResult numOfRows]) - [queryResult dataSeek:0]; - for (i = 0 ; i < [queryResult numOfRows] ; i++) - { - // [possibleCompletions addObject:[[queryResult fetchRowAsArray] objectAtIndex:1]]; - [possibleCompletions addObject:[NSDictionary dictionaryWithObjectsAndKeys:NSArrayObjectAtIndex([queryResult fetchRowAsArray], 1), @"display", @"func-small", @"image", nil]]; - } + for (id obj in [[[[self window] delegate] valueForKeyPath:@"tablesListInstance"] valueForKey:@"allFunctionNames"]) + [possibleCompletions addObject:[NSDictionary dictionaryWithObjectsAndKeys:obj, @"display", @"func-small", @"image", nil]]; } } @@ -927,51 +903,23 @@ NSInteger alphabeticSort(id string1, id string2, void *reverse) if([mySQLConnection isConnected]) { + + // Add all database names to completions list + [possibleCompletions addObjectsFromArray:[[[[self window] delegate] valueForKeyPath:@"tablesListInstance"] valueForKey:@"allDatabaseNames"]]; + // Add table names to completions list - MCPResult *queryResult = [mySQLConnection listTables]; - if ([queryResult numOfRows]) - [queryResult dataSeek:0]; - for (i = 0 ; i < [queryResult numOfRows] ; i++) - { - [possibleCompletions addObject:[[queryResult fetchRowAsArray] objectAtIndex:0]]; - } + [possibleCompletions addObjectsFromArray:[[[[self window] delegate] valueForKeyPath:@"tablesListInstance"] valueForKey:@"allTableAndViewNames"]]; // Add field names to completions list for currently selected table - if ([[[self window] delegate] table] != nil) { - id columnNames = [[[[self window] delegate] valueForKeyPath:@"tableDataInstance"] valueForKey:@"columnNames"]; - [possibleCompletions addObjectsFromArray:columnNames]; - } - - // Add all database names to completions list - queryResult = [mySQLConnection listDBs]; - if ([queryResult numOfRows]) - [queryResult dataSeek:0]; - for (i = 0 ; i < [queryResult numOfRows] ; i++) - { - [possibleCompletions addObject:[[queryResult fetchRowAsArray] objectAtIndex:0]]; - } + if ([[[self window] delegate] table] != nil) + [possibleCompletions addObjectsFromArray:[[[[self window] delegate] valueForKeyPath:@"tableDataInstance"] valueForKey:@"columnNames"]]; // Add proc/func only for MySQL version 5 or higher if(mySQLmajorVersion > 4) { - // Add all procedures to completions list for currently selected table - queryResult = [mySQLConnection queryString:@"SHOW PROCEDURE STATUS"]; - if ([queryResult numOfRows]) - [queryResult dataSeek:0]; - for (i = 0 ; i < [queryResult numOfRows] ; i++) - { - [possibleCompletions addObject:[[queryResult fetchRowAsArray] objectAtIndex:1]]; - } - - // Add all function to completions list for currently selected table - queryResult = [mySQLConnection queryString:@"SHOW FUNCTION STATUS"]; - if ([queryResult numOfRows]) - [queryResult dataSeek:0]; - for (i = 0 ; i < [queryResult numOfRows] ; i++) - { - [possibleCompletions addObject:[[queryResult fetchRowAsArray] objectAtIndex:1]]; - } + [possibleCompletions addObjectsFromArray:[[[[self window] delegate] valueForKeyPath:@"tablesListInstance"] valueForKey:@"allProcedureNames"]]; + [possibleCompletions addObjectsFromArray:[[[[self window] delegate] valueForKeyPath:@"tablesListInstance"] valueForKey:@"allFunctionNames"]]; } - + } // If caret is not inside backticks add keywords and all words coming from the view. if(![[[self textStorage] attribute:kBTQuote atIndex:charRange.location effectiveRange:nil] isEqualToString:kBTQuoteValue] ) diff --git a/Source/TableDocument.h b/Source/TableDocument.h index 4816b4a3..8272cd62 100644 --- a/Source/TableDocument.h +++ b/Source/TableDocument.h @@ -100,6 +100,8 @@ NSToolbarItem *chooseDatabaseToolbarItem; WebView *printWebView; + + NSMutableArray *allDatabases; } - (NSString *)getHTMLforPrint; @@ -117,6 +119,7 @@ - (IBAction)removeDatabase:(id)sender; - (IBAction)showMySQLHelp:(id)sender; - (IBAction)saveServerVariables:(id)sender; +- (NSArray *)allDatabaseNames; //encoding methods - (void)setConnectionEncoding:(NSString *)mysqlEncoding reloadingViews:(BOOL)reloadViews; diff --git a/Source/TableDocument.m b/Source/TableDocument.m index f4383535..cbcc13b7 100644 --- a/Source/TableDocument.m +++ b/Source/TableDocument.m @@ -70,8 +70,9 @@ [printWebView setFrameLoadDelegate:self]; prefs = [NSUserDefaults standardUserDefaults]; + } - + return self; } @@ -349,12 +350,19 @@ [queryResult dataSeek:0]; } - int i; - - for (i = 0 ; i < [queryResult numOfRows] ; i++) - { - [chooseDatabaseButton addItemWithTitle:NSArrayObjectAtIndex([queryResult fetchRowAsArray], 0)]; - } + // if([allDatabases count]) + // [allDatabases removeAllObjects]; + + if(allDatabases) + [allDatabases release]; + + allDatabases = [[NSMutableArray alloc] initWithCapacity:[queryResult numOfRows]]; + + for (int i = 0 ; i < [queryResult numOfRows] ; i++) + [allDatabases addObject:NSArrayObjectAtIndex([queryResult fetchRowAsArray], 0)]; + + for (id db in allDatabases) + [chooseDatabaseButton addItemWithTitle:db]; (![self database]) ? [chooseDatabaseButton selectItemAtIndex:0] : [chooseDatabaseButton selectItemWithTitle:[self database]]; } @@ -494,6 +502,14 @@ [alert beginSheetModalForWindow:tableWindow modalDelegate:self didEndSelector:@selector(sheetDidEnd:returnCode:contextInfo:) contextInfo:@"removedatabase"]; } +/* + * Returns an array of all available database names + */ +- (NSArray *)allDatabaseNames +{ + return allDatabases; +} + /** * alert sheets method * invoked when alertSheet get closed @@ -2127,7 +2143,7 @@ [selectedDatabase release]; [mySQLVersion release]; [connectionController release]; - + [allDatabases release]; [super dealloc]; } diff --git a/Source/TablesList.h b/Source/TablesList.h index 8a13e487..965f00be 100644 --- a/Source/TablesList.h +++ b/Source/TablesList.h @@ -110,6 +110,12 @@ enum sp_table_types - (int)tableType; - (NSArray *)tables; - (NSArray *)tableTypes; +- (NSArray *)allTableAndViewNames; +- (NSArray *)allTableNames; +- (NSArray *)allViewNames; +- (NSArray *)allFunctionNames; +- (NSArray *)allProcedureNames; +- (NSArray *)allDatabaseNames; - (BOOL)structureLoaded; - (BOOL)contentLoaded; - (BOOL)statusLoaded; diff --git a/Source/TablesList.m b/Source/TablesList.m index ec330d9a..49b97008 100644 --- a/Source/TablesList.m +++ b/Source/TablesList.m @@ -930,6 +930,78 @@ } /** + * Database tables accessors for a given table type + */ +- (NSArray *)allTableAndViewNames +{ + NSMutableArray *returnArray = [NSMutableArray array]; + int i; + int cnt = [[self tables] count]; + for(i=0; i<cnt; i++) { + if([NSArrayObjectAtIndex([self tableTypes],i) intValue] == SP_TABLETYPE_TABLE || [NSArrayObjectAtIndex([self tableTypes],i) intValue] == SP_TABLETYPE_VIEW) + [returnArray addObject:NSArrayObjectAtIndex([self tables], i)]; + } + [returnArray sortUsingSelector:@selector(compare:)]; + return returnArray; +} +- (NSArray *)allTableNames +{ + NSMutableArray *returnArray = [NSMutableArray array]; + int i; + int cnt = [[self tables] count]; + for(i=0; i<cnt; i++) { + if([NSArrayObjectAtIndex([self tableTypes],i) intValue] == SP_TABLETYPE_TABLE) + [returnArray addObject:NSArrayObjectAtIndex([self tables], i)]; + } + [returnArray sortUsingSelector:@selector(compare:)]; + return returnArray; +} +- (NSArray *)allViewNames +{ + NSMutableArray *returnArray = [NSMutableArray array]; + int i; + int cnt = [[self tables] count]; + for(i=0; i<cnt; i++) { + if([NSArrayObjectAtIndex([self tableTypes],i) intValue] == SP_TABLETYPE_VIEW) + [returnArray addObject:NSArrayObjectAtIndex([self tables], i)]; + } + [returnArray sortUsingSelector:@selector(compare:)]; + return returnArray; +} +- (NSArray *)allProcedureNames +{ + NSMutableArray *returnArray = [NSMutableArray array]; + int i; + int cnt = [[self tables] count]; + for(i=0; i<cnt; i++) { + if([NSArrayObjectAtIndex([self tableTypes],i) intValue] == SP_TABLETYPE_PROC) + [returnArray addObject:NSArrayObjectAtIndex([self tables], i)]; + } + [returnArray sortUsingSelector:@selector(compare:)]; + return returnArray; +} +- (NSArray *)allFunctionNames +{ + NSMutableArray *returnArray = [NSMutableArray array]; + int i; + int cnt = [[self tables] count]; + for(i=0; i<cnt; i++) { + if([NSArrayObjectAtIndex([self tableTypes],i) intValue] == SP_TABLETYPE_FUNC) + [returnArray addObject:NSArrayObjectAtIndex([self tables], i)]; + } + [returnArray sortUsingSelector:@selector(compare:)]; + return returnArray; +} + +/** + * Returns an array of all available database names + */ +- (NSArray *)allDatabaseNames +{ + return [tableDocumentInstance allDatabaseNames]; +} + +/** * Database table types accessor */ - (NSArray *)tableTypes |