aboutsummaryrefslogtreecommitdiffstats
path: root/Source
diff options
context:
space:
mode:
authorBibiko <bibiko@eva.mpg.de>2010-03-29 12:10:44 +0000
committerBibiko <bibiko@eva.mpg.de>2010-03-29 12:10:44 +0000
commitae0de60e69ffd51cda85ff70417cd354ee781c1c (patch)
treefb8119cd9eccfc12281d833bbffd103ef0e4c7c4 /Source
parent24b365b2a177d7de4cdbb7601424b6b1098a8414 (diff)
downloadsequelpro-ae0de60e69ffd51cda85ff70417cd354ee781c1c.tar.gz
sequelpro-ae0de60e69ffd51cda85ff70417cd354ee781c1c.tar.bz2
sequelpro-ae0de60e69ffd51cda85ff70417cd354ee781c1c.zip
• fixed several issue for completion lists
• improved gathering and caching of structure data coming from connection windows with the same connection • made the structure querying more stable against threading issues • moved getUniqueDbIdentifierFor from MCPConnection to SPNavigatorController to be up-to-date in all connection windows • improved detection if db structure querying should be performed or not (not yet finished)
Diffstat (limited to 'Source')
-rw-r--r--Source/CMTextView.m4
-rw-r--r--Source/SPNavigatorController.h4
-rw-r--r--Source/SPNavigatorController.m104
-rw-r--r--Source/TableDocument.h2
-rw-r--r--Source/TableDocument.m10
5 files changed, 97 insertions, 27 deletions
diff --git a/Source/CMTextView.m b/Source/CMTextView.m
index abc37865..3884f993 100644
--- a/Source/CMTextView.m
+++ b/Source/CMTextView.m
@@ -363,9 +363,9 @@ NSInteger alphabeticSort(id string1, id string2, void *reverse)
BOOL aTableNameExists = NO;
if(!aDbName) {
- // Try to suggest only items which are uniquely valid for the parsed string
- NSInteger uniqueSchemaKind = [mySQLConnection getUniqueDbIdentifierFor:[aTableName lowercaseString]];
+ // Try to suggest only items which are uniquely valid for the parsed string
+ NSInteger uniqueSchemaKind = [[SPNavigatorController sharedNavigatorController] getUniqueDbIdentifierFor:[aTableName lowercaseString] andConnection:[[[self delegate] valueForKeyPath:@"tableDocumentInstance"] connectionID]];
// If no db name but table name check if table name is a valid name in the current selected db
if(aTableName && [aTableName length]
diff --git a/Source/SPNavigatorController.h b/Source/SPNavigatorController.h
index 9181dbaf..4affe9ef 100644
--- a/Source/SPNavigatorController.h
+++ b/Source/SPNavigatorController.h
@@ -71,6 +71,10 @@
- (void)isUpdatingNavigator:(NSNotification *)aNotification;
- (NSDictionary *)dbStructureForConnection:(NSString*)connectionID;
+- (NSArray *)allSchemaKeysForConnection:(NSString*)connectionID;
+- (NSInteger)getUniqueDbIdentifierFor:(NSString*)term andConnection:(NSString*)connectionID;
+
+- (BOOL)isUpdatingConnection:(NSString*)connectionID;
- (void)restoreSelectedItems;
- (void)setIgnoreUpdate:(BOOL)flag;
diff --git a/Source/SPNavigatorController.m b/Source/SPNavigatorController.m
index dcc22c63..31a6b44d 100644
--- a/Source/SPNavigatorController.m
+++ b/Source/SPNavigatorController.m
@@ -384,7 +384,10 @@ static SPNavigatorController *sharedNavigatorController = nil;
- (void)isUpdatingNavigator:(NSNotification *)aNotification
{
- // todo
+ id object = [aNotification object];
+
+ if([object isKindOfClass:[TableDocument class]])
+ [updatingConnections addObject:[object connectionID]];
}
- (void)updateEntriesForConnection:(NSString*)connectionID
@@ -400,37 +403,43 @@ static SPNavigatorController *sharedNavigatorController = nil;
[infoArray removeAllObjects];
if ([[[NSDocumentController sharedDocumentController] documents] count]) {
- for(id doc in [[NSDocumentController sharedDocumentController] documents]) {
- id theConnection = [doc valueForKeyPath:@"mySQLConnection"];
+ id doc = [[NSDocumentController sharedDocumentController] currentDocument];
+ id theConnection = [doc valueForKeyPath:@"mySQLConnection"];
- if(!theConnection || ![theConnection isConnected]) continue;
+ if(!theConnection || ![theConnection isConnected]) return;
- NSString *connectionName = [doc connectionID];
+ NSString *connectionName = [doc connectionID];
- if(!connectionName || [connectionName isEqualToString:@"_"] || (connectionID && ![connectionName isEqualToString:connectionID]) ) continue;
+ if(!connectionName || [connectionName isEqualToString:@"_"] || (connectionID && ![connectionName isEqualToString:connectionID]) ) {
+// NSLog(@"navigator update skipped %@", connectionName);
+ return;
+ }
- if(![schemaData objectForKey:connectionName]) {
- [schemaData setObject:[NSMutableDictionary dictionary] forKey:connectionName];
- }
+ if(![schemaData objectForKey:connectionName]) {
+ [schemaData setObject:[NSMutableDictionary dictionary] forKey:connectionName];
+ }
- NSArray *dbs = [doc allDatabaseNames];
- NSArray *keys = [[schemaData objectForKey:connectionName] allKeys];
- for(id db in keys) {
- if(![dbs containsObject:[[db componentsSeparatedByString:SPUniqueSchemaDelimiter] objectAtIndex:1]]) {
- [[schemaData objectForKey:connectionName] removeObjectForKey:db];
- }
+ // Remove deleted dbs
+ NSArray *dbs = [doc allDatabaseNames];
+ NSArray *keys = [[schemaData objectForKey:connectionName] allKeys];
+ for(id db in keys) {
+ if(![dbs containsObject:[[db componentsSeparatedByString:SPUniqueSchemaDelimiter] objectAtIndex:1]]) {
+ [[schemaData objectForKey:connectionName] removeObjectForKey:db];
}
+ }
+ id structureData = [theConnection getDbStructure];
+ if(structureData && [structureData objectForKey:connectionName] && [[structureData objectForKey:connectionName] isKindOfClass:[NSDictionary class]]) {
+ for(id item in [[structureData objectForKey:connectionName] allKeys])
+ [[schemaData objectForKey:connectionName] setObject:[[structureData objectForKey:connectionName] objectForKey:item] forKey:item];
- if([theConnection getDbStructure] && [[theConnection getDbStructure] objectForKey:connectionName]) {
- for(id item in [[[theConnection getDbStructure] objectForKey:connectionName] allKeys])
- [[schemaData objectForKey:connectionName] setObject:[[[theConnection getDbStructure] objectForKey:connectionName] objectForKey:item] forKey:item];
+ if([theConnection getAllKeysOfDbStructure])
[allSchemaKeys setObject:[theConnection getAllKeysOfDbStructure] forKey:connectionName];
- } else {
- [schemaData setObject:[NSDictionary dictionary] forKey:[NSString stringWithFormat:@"%@&DEL&no data loaded yet", connectionName]];
- [allSchemaKeys setObject:[NSArray array] forKey:connectionName];
- }
+ } else {
+ [schemaData setObject:[NSDictionary dictionary] forKey:[NSString stringWithFormat:@"%@&DEL&no data loaded yet", connectionName]];
+ [allSchemaKeys setObject:[NSArray array] forKey:connectionName];
}
+ [updatingConnections removeObject:connectionName];
[outlineSchema1 reloadData];
[outlineSchema2 reloadData];
@@ -450,9 +459,7 @@ static SPNavigatorController *sharedNavigatorController = nil;
{
NSString *db_id = [NSString stringWithFormat:@"%@%@%@", connectionID, SPUniqueSchemaDelimiter, dbname];
- if([[[schemaData objectForKey:connectionID] allKeys] containsObject:db_id]
- && [[[schemaData objectForKey:connectionID] objectForKey:db_id] isKindOfClass:[NSDictionary class]]
- && [[[schemaData objectForKey:connectionID] objectForKey:db_id] count])
+ if([schemaData objectForKey:connectionID] && [[[schemaData objectForKey:connectionID] allKeys] containsObject:db_id])
return YES;
return NO;
@@ -472,6 +479,53 @@ static SPNavigatorController *sharedNavigatorController = nil;
return nil;
}
+- (NSArray *)allSchemaKeysForConnection:(NSString*)connectionID
+{
+ return [NSArray arrayWithArray:[allSchemaKeys objectForKey:connectionID]];
+}
+
+/**
+ * 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)getUniqueDbIdentifierFor:(NSString*)term andConnection:(NSString*)connectionID
+{
+
+ NSString *SPUniqueSchemaDelimiter = @"￸";
+
+ NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF ENDSWITH[c] %@", [NSString stringWithFormat:@"%@%@", SPUniqueSchemaDelimiter, [term lowercaseString]]];
+ NSArray *result = [[allSchemaKeys objectForKey:connectionID] filteredArrayUsingPredicate:predicate];
+
+ if([result count] < 1 ) return 0;
+ if([result count] == 1) {
+ NSArray *split = [[result objectAtIndex:0] componentsSeparatedByString:SPUniqueSchemaDelimiter];
+ if([split count] == 2 ) return 1;
+ if([split count] == 3 ) return 2;
+ return 0;
+ }
+ // case if field is equal to a table or db name
+ NSMutableArray *arr = [NSMutableArray array];
+ for(NSString *item in result) {
+ if([[item componentsSeparatedByString:SPUniqueSchemaDelimiter] count] < 4)
+ [arr addObject:item];
+ }
+ if([arr count] < 1 ) return 0;
+ if([arr count] == 1) {
+ NSArray *split = [[arr objectAtIndex:0] componentsSeparatedByString:SPUniqueSchemaDelimiter];
+ if([split count] == 2 ) return 1;
+ if([split count] == 3 ) return 2;
+ return 0;
+ }
+ return 0;
+}
+
+
+- (BOOL)isUpdatingConnection:(NSString*)connectionID
+{
+ return ([updatingConnections containsObject:connectionID]) ? YES : NO;
+}
+
#pragma mark -
#pragma mark IBActions
diff --git a/Source/TableDocument.h b/Source/TableDocument.h
index 4a943302..5f173f9d 100644
--- a/Source/TableDocument.h
+++ b/Source/TableDocument.h
@@ -190,6 +190,8 @@
- (NSArray *)allDatabaseNames;
- (NSArray *)allSystemDatabaseNames;
- (BOOL)navigatorSchemaPathExistsForDatabase:(NSString*)dbname;
+- (NSDictionary *)getDbStructure;
+- (NSArray *)allSchemaKeys;
// Task progress and notification methods
- (void)startTaskWithDescription:(NSString *)description;
diff --git a/Source/TableDocument.m b/Source/TableDocument.m
index 2a95c158..936792b2 100644
--- a/Source/TableDocument.m
+++ b/Source/TableDocument.m
@@ -1092,6 +1092,16 @@
return [[SPNavigatorController sharedNavigatorController] schemaPathExistsForConnection:[self connectionID] andDatabase:dbname];
}
+- (NSDictionary*)getDbStructure
+{
+ return [[SPNavigatorController sharedNavigatorController] dbStructureForConnection:[self connectionID]];
+}
+
+- (NSArray *)allSchemaKeys
+{
+ return [[SPNavigatorController sharedNavigatorController] allSchemaKeysForConnection:[self connectionID]];
+}
+
#pragma mark -
#pragma mark Console methods