aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBibiko <bibiko@eva.mpg.de>2010-01-14 10:04:08 +0000
committerBibiko <bibiko@eva.mpg.de>2010-01-14 10:04:08 +0000
commitc6b739f9927b6ed0feebf7515db02899b2424382 (patch)
treed31f6eab06fb94bfec0f9df2bbd3e942576ba536
parent0b48b40370b5a49144f39ae95888f3fbcd1aa048 (diff)
downloadsequelpro-c6b739f9927b6ed0feebf7515db02899b2424382.tar.gz
sequelpro-c6b739f9927b6ed0feebf7515db02899b2424382.tar.bz2
sequelpro-c6b739f9927b6ed0feebf7515db02899b2424382.zip
• added method to get an info about unique database/tables names for completion
-rw-r--r--Frameworks/MCPKit/MCPFoundationKit/MCPConnection.h2
-rw-r--r--Frameworks/MCPKit/MCPFoundationKit/MCPConnection.m41
2 files changed, 42 insertions, 1 deletions
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).