diff options
author | Bibiko <bibiko@eva.mpg.de> | 2009-07-14 19:34:40 +0000 |
---|---|---|
committer | Bibiko <bibiko@eva.mpg.de> | 2009-07-14 19:34:40 +0000 |
commit | 0612652448f32e620a96e923a44b463fa1b9e0dc (patch) | |
tree | c77ff4cd7596aed10e445d0051620ecfbe295f7e /Source/CMTextView.m | |
parent | 6686223d2c30a7b99b8de11a8659851725f6326f (diff) | |
download | sequelpro-0612652448f32e620a96e923a44b463fa1b9e0dc.tar.gz sequelpro-0612652448f32e620a96e923a44b463fa1b9e0dc.tar.bz2 sequelpro-0612652448f32e620a96e923a44b463fa1b9e0dc.zip |
• fix for completion in CustomQuery editor
- now the gathering of suggestions does not query the MySQL connection, instead it uses the TableList/TableDocument tableView data as a kind of cache
- this approach should improve the speed for slow server connections
TODO: auto-update for TableList and Database List resp. (it could happen that an other user changed the name of a table/db meanwhile)
Diffstat (limited to 'Source/CMTextView.m')
-rw-r--r-- | Source/CMTextView.m | 104 |
1 files changed, 26 insertions, 78 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] ) |