From c6b739f9927b6ed0feebf7515db02899b2424382 Mon Sep 17 00:00:00 2001 From: Bibiko Date: Thu, 14 Jan 2010 10:04:08 +0000 Subject: =?UTF-8?q?=E2=80=A2=20added=20method=20to=20get=20an=20info=20abo?= =?UTF-8?q?ut=20unique=20database/tables=20names=20for=20completion?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Frameworks/MCPKit/MCPFoundationKit/MCPConnection.h | 2 ++ Frameworks/MCPKit/MCPFoundationKit/MCPConnection.m | 41 +++++++++++++++++++++- 2 files changed, 42 insertions(+), 1 deletion(-) (limited to 'Frameworks/MCPKit/MCPFoundationKit') diff --git a/Frameworks/MCPKit/MCPFoundationKit/MCPConnection.h b/Frameworks/MCPKit/MCPFoundationKit/MCPConnection.h index 8398f4ca..68875bb7 100644 --- a/Frameworks/MCPKit/MCPFoundationKit/MCPConnection.h +++ b/Frameworks/MCPKit/MCPFoundationKit/MCPConnection.h @@ -106,6 +106,7 @@ static inline NSData* NSStringDataUsingLossyEncoding(NSString* self, NSInteger e NSString *serverVersionString; NSDictionary *theDbStructure; + NSDictionary *uniqueDbIdentifier; NSTimer *keepAliveTimer; pthread_t keepAliveThread; @@ -229,6 +230,7 @@ void performThreadedKeepAlive(void *ptr); - (MCPResult *)listFieldsFromTable:(NSString *)tableName like:(NSString *)fieldsName; - (void)queryDbStructure; - (NSDictionary *)getDbStructure; +- (NSInteger)getUniqueDbIndentifierFor:(NSString*)term; // Server information - (NSString *)clientInfo; diff --git a/Frameworks/MCPKit/MCPFoundationKit/MCPConnection.m b/Frameworks/MCPKit/MCPFoundationKit/MCPConnection.m index 3e17944f..cda82647 100644 --- a/Frameworks/MCPKit/MCPFoundationKit/MCPConnection.m +++ b/Frameworks/MCPKit/MCPFoundationKit/MCPConnection.m @@ -1883,6 +1883,9 @@ void performThreadedKeepAlive(void *ptr) if (mysql_real_query(structConnection, queryCString, queryCStringLength) == 0) { theResult = mysql_use_result(structConnection); NSMutableDictionary *structure = [NSMutableDictionary dictionary]; + NSMutableSet *namesSet = [[NSMutableSet alloc] initWithCapacity:20]; + NSMutableArray *allDbNames = [NSMutableArray array]; + NSMutableArray *allTableNames = [NSMutableArray array]; while(row = mysql_fetch_row(theResult)) { NSString *db = [self stringWithUTF8CString:row[0]]; @@ -1892,6 +1895,11 @@ void performThreadedKeepAlive(void *ptr) NSString *charset = (row[4]) ? [self stringWithUTF8CString:row[4]] : @""; NSString *structtype = [self stringWithUTF8CString:row[5]]; + [namesSet addObject:[db lowercaseString]]; + [namesSet addObject:[table lowercaseString]]; + [allDbNames addObject:[db lowercaseString]]; + [allTableNames addObject:[table lowercaseString]]; + if(![structure valueForKey:db]) { [structure setObject:[NSMutableDictionary dictionary] forKey:db]; } @@ -1907,12 +1915,31 @@ void performThreadedKeepAlive(void *ptr) mysql_free_result(theResult); mysql_close(structConnection); + if(theDbStructure != nil) { [theDbStructure release]; theDbStructure = nil; } - theDbStructure = [[NSDictionary dictionaryWithDictionary:structure] retain]; + + NSMutableDictionary *uniqueIdentifier = [NSMutableDictionary dictionary]; + for(id name in namesSet) { + if([allDbNames containsObject:name] && [allTableNames containsObject:name]) { + ; + } else { + if([allDbNames containsObject:name]) + [uniqueIdentifier setObject:[NSNumber numberWithInteger:1] forKey:name]; + else + [uniqueIdentifier setObject:[NSNumber numberWithInteger:2] forKey:name]; + } + } + [namesSet release]; + if(uniqueDbIdentifier != nil) { + [uniqueDbIdentifier release]; + uniqueDbIdentifier = nil; + } + uniqueDbIdentifier = [[NSDictionary dictionaryWithDictionary:uniqueIdentifier] retain]; + isQueryingDbStructure = NO; [queryPool release]; return; @@ -1926,6 +1953,18 @@ void performThreadedKeepAlive(void *ptr) [queryPool release]; } +/** + * Returns 1 for db and 2 for table name if table name is not a db name and versa visa. + * Otherwise it return 0. Mainly used for completion to know whether a `foo`. can only be + * a db name or a table name. + */ +- (NSInteger)getUniqueDbIndentifierFor:(NSString*)term +{ + if([uniqueDbIdentifier objectForKey:term]) + return [[uniqueDbIdentifier objectForKey:term] integerValue]; + else + return 0; +} /** * Returns a dict containing the structure of all available databases (mainly for completion). -- cgit v1.2.3