From 14b3a654bad83e021aa80e0838b6b72ca79ac9d6 Mon Sep 17 00:00:00 2001 From: Bibiko Date: Wed, 20 May 2009 15:25:57 +0000 Subject: =?UTF-8?q?=E2=80=A2=20made=20mySQLConnection=20reachable=20for=20?= =?UTF-8?q?CMTextView=20=E2=80=A2=20for=20MySQL=20version=20>=204=20added?= =?UTF-8?q?=20proc/func=20names=20to=20the=20completion=20suggestion=20lis?= =?UTF-8?q?t=20=E2=80=A2=20changed=20the=20way=20of=20adding=20the=20table?= =?UTF-8?q?=20names=20to=20the=20completion=20suggestion=20list=20=20-=20n?= =?UTF-8?q?ow=20it=20uses=20[mySQLConnection=20listTables]=20instead=20of?= =?UTF-8?q?=20taking=20the=20names=20from=20the=20table=20view=20list=20du?= =?UTF-8?q?e=20to=20the=20header=20items=20=E2=80=A2=20added=20some=20prag?= =?UTF-8?q?ma=20marks=20to=20CMTextView?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Source/CMTextView.h | 4 +++ Source/CMTextView.m | 86 ++++++++++++++++++++++++++++++++++++++++------------ Source/CustomQuery.m | 2 ++ 3 files changed, 73 insertions(+), 19 deletions(-) (limited to 'Source') diff --git a/Source/CMTextView.h b/Source/CMTextView.h index 37731784..fad867e2 100644 --- a/Source/CMTextView.h +++ b/Source/CMTextView.h @@ -47,6 +47,9 @@ NSUserDefaults *prefs; + CMMCPConnection *mySQLConnection; + int mySQLmajorVersion; + } - (IBAction)showMySQLHelpForCurrentWord:(id)sender; @@ -77,5 +80,6 @@ - (unsigned int) characterIndexOfPoint:(NSPoint)aPoint; - (void) makeTextSizeLarger; - (void) makeTextSizeSmaller; +- (void) setConnection:(CMMCPConnection *)theConnection withVersion:(int)majorVersion; @end diff --git a/Source/CMTextView.m b/Source/CMTextView.m index 48832133..59cd0092 100644 --- a/Source/CMTextView.m +++ b/Source/CMTextView.m @@ -28,6 +28,10 @@ #import "SPStringAdditions.h" #import "SPTextViewAdditions.h" + +#pragma mark - +#pragma mark lex init + /* * Include all the extern variables and prototypes required for flex (used for syntax highlighting) */ @@ -38,6 +42,9 @@ typedef struct yy_buffer_state *YY_BUFFER_STATE; void yy_switch_to_buffer(YY_BUFFER_STATE); YY_BUFFER_STATE yy_scan_string (const char *); +#pragma mark - +#pragma mark attribute definition + #define kAPlinked @"Linked" // attribute for a via auto-pair inserted char #define kAPval @"linked" #define kLEXToken @"Quoted" // set via lex to indicate a quoted string @@ -49,14 +56,18 @@ YY_BUFFER_STATE yy_scan_string (const char *); #define kBTQuote @"BTQuote" #define kBTQuoteValue @"isBTQuoted" +#pragma mark - +#pragma mark constant definitions + #define SP_CQ_SEARCH_IN_MYSQL_HELP_MENU_ITEM_TAG 1000 #define SP_CQ_COPY_AS_RTF_MENU_ITEM_TAG 1001 #define SP_SYNTAX_HILITE_BIAS 2000 - #define MYSQL_DOC_SEARCH_URL @"http://dev.mysql.com/doc/refman/%@/en/%@.html" +#pragma mark - + @implementation CMTextView - (void) awakeFromNib @@ -87,9 +98,14 @@ YY_BUFFER_STATE yy_scan_string (const char *); [aNotificationCenter addObserver:self selector:@selector(boundsDidChangeNotification:) name:@"NSViewBoundsDidChangeNotification" object:[scrollView contentView]]; prefs = [[NSUserDefaults standardUserDefaults] retain]; - + +} +- (void) setConnection:(CMMCPConnection *)theConnection withVersion:(int)majorVersion +{ + mySQLConnection = theConnection; + NSLog(@"%d", majorVersion); + mySQLmajorVersion = majorVersion; } - /* * Returns the associated line number for a character position inside of the CMTextView @@ -683,25 +699,55 @@ YY_BUFFER_STATE yy_scan_string (const char *); unsigned i, insindex; insindex = 0; - // Add current table names omitting the first item (it's the table header) - id tableNames = [[[[self window] delegate] valueForKeyPath:@"tablesListInstance"] valueForKey:@"tables"]; - [possibleCompletions addObjectsFromArray:[tableNames objectsAtIndexes:[NSIndexSet indexSetWithIndexesInRange:NSMakeRange(1, [tableNames count]-1)]]]; - - // Add column 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 - MCPResult *queryResult = [[[[self window] delegate] valueForKeyPath:@"mySQLConnection"] valueForKey:@"listDBs"]; - if ([queryResult numOfRows]) - [queryResult dataSeek:0]; - for (i = 0 ; i < [queryResult numOfRows] ; i++) + if([mySQLConnection isConnected]) { - [possibleCompletions addObject:[[queryResult fetchRowAsArray] objectAtIndex:0]]; - } + // 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]]; + } + + // 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]]; + } + + // 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]]; + } + } + + } // 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] ) { @@ -730,6 +776,8 @@ YY_BUFFER_STATE yy_scan_string (const char *); [compl addObject:obj]; } + [possibleCompletions release]; + return [compl autorelease]; } diff --git a/Source/CustomQuery.m b/Source/CustomQuery.m index 9245d953..3aa90ce0 100644 --- a/Source/CustomQuery.m +++ b/Source/CustomQuery.m @@ -1403,6 +1403,8 @@ traps enter key and - (void)setMySQLversion:(NSString *)theVersion { mySQLversion = [[theVersion substringToIndex:3] retain]; + [textView setConnection:mySQLConnection withVersion:[[[mySQLversion componentsSeparatedByString:@"."] objectAtIndex:0] intValue]]; + } /* -- cgit v1.2.3