aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBibiko <bibiko@eva.mpg.de>2010-11-04 17:03:12 +0000
committerBibiko <bibiko@eva.mpg.de>2010-11-04 17:03:12 +0000
commit65670f060759c2d5f096db401390da47b9365706 (patch)
tree4c34858715090715eb49e3ba50a9b93034430a75
parent286d4ef211a7ab3e9564bbe6a099021e0064c941 (diff)
downloadsequelpro-65670f060759c2d5f096db401390da47b9365706.tar.gz
sequelpro-65670f060759c2d5f096db401390da47b9365706.tar.bz2
sequelpro-65670f060759c2d5f096db401390da47b9365706.zip
• alias (auto-)completion
- further improvements to match table names
-rw-r--r--Source/SPNavigatorController.h2
-rw-r--r--Source/SPNavigatorController.m14
-rw-r--r--Source/SPTextView.m12
3 files changed, 19 insertions, 9 deletions
diff --git a/Source/SPNavigatorController.h b/Source/SPNavigatorController.h
index f21c03c5..045e5eb4 100644
--- a/Source/SPNavigatorController.h
+++ b/Source/SPNavigatorController.h
@@ -77,7 +77,7 @@
- (NSDictionary *)dbStructureForConnection:(NSString*)connectionID;
- (NSArray *)allSchemaKeysForConnection:(NSString*)connectionID;
-- (NSArray *)getUniqueDbIdentifierFor:(NSString*)term andConnection:(NSString*)connectionID;
+- (NSArray *)getUniqueDbIdentifierFor:(NSString*)term andConnection:(NSString*)connectionID ignoreFields:(BOOL)ignoreFields;
- (BOOL)isUpdatingConnection:(NSString*)connectionID;
- (BOOL)isUpdating;
diff --git a/Source/SPNavigatorController.m b/Source/SPNavigatorController.m
index 58141936..aeb5af8c 100644
--- a/Source/SPNavigatorController.m
+++ b/Source/SPNavigatorController.m
@@ -508,13 +508,23 @@ static NSComparisonResult compareStrings(NSString *s1, NSString *s2, void* conte
* Otherwise it return 0. Mainly used for completion to know whether a `foo`. can only be
* a db name or a table name.
*/
-- (NSArray *)getUniqueDbIdentifierFor:(NSString*)term andConnection:(NSString*)connectionID
+- (NSArray *)getUniqueDbIdentifierFor:(NSString*)term andConnection:(NSString*)connectionID ignoreFields:(BOOL)ignoreFields
{
NSString *SPUniqueSchemaDelimiter = @"￸";
NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF ENDSWITH[c] %@", [NSString stringWithFormat:@"%@%@", SPUniqueSchemaDelimiter, [term lowercaseString]]];
- NSArray *result = [[allSchemaKeys objectForKey:connectionID] filteredArrayUsingPredicate:predicate];
+ NSMutableArray *result = [NSMutableArray arrayWithCapacity:5];
+
+ NSString *re = [NSString stringWithFormat:@"%@.*?%@.*?%@", SPUniqueSchemaDelimiter, SPUniqueSchemaDelimiter, SPUniqueSchemaDelimiter];
+ for(id r in [[allSchemaKeys objectForKey:connectionID] filteredArrayUsingPredicate:predicate]) {
+ if(ignoreFields) {
+ if(![r isMatchedByRegex:re])
+ [result addObject:r];
+ } else {
+ [result addObject:r];
+ }
+ }
if([result count] < 1 ) return [NSArray arrayWithObjects:[NSNumber numberWithInt:0], @"", nil];
if([result count] == 1) {
diff --git a/Source/SPTextView.m b/Source/SPTextView.m
index a1797521..892fc744 100644
--- a/Source/SPTextView.m
+++ b/Source/SPTextView.m
@@ -364,14 +364,14 @@ NSInteger alphabeticSort(id string1, id string2, void *reverse)
if(!aDbName) {
// Try to suggest only items which are uniquely valid for the parsed string
- NSArray *uniqueSchema = [[SPNavigatorController sharedNavigatorController] getUniqueDbIdentifierFor:[aTableName lowercaseString] andConnection:[[[self delegate] valueForKeyPath:@"tableDocumentInstance"] connectionID]];
+ NSArray *uniqueSchema = [[SPNavigatorController sharedNavigatorController] getUniqueDbIdentifierFor:[aTableName lowercaseString] andConnection:[[[self delegate] valueForKeyPath:@"tableDocumentInstance"] connectionID] ignoreFields:YES];
NSInteger uniqueSchemaKind = [[uniqueSchema objectAtIndex:0] intValue];
// If no db name but table name check if table name is a valid name in the current selected db
- if(aTableName && [aTableName length]
+ if(uniqueSchemaKind == 2 && aTableName && [aTableName length]
&& [dbs objectForKey:currentDb] && [[dbs objectForKey:currentDb] isKindOfClass:[NSDictionary class]]
- && [[dbs objectForKey:currentDb] objectForKey:[NSString stringWithFormat:@"%@%@%@", currentDb, SPUniqueSchemaDelimiter, [uniqueSchema objectAtIndex:1]]]
- && uniqueSchemaKind == 2) {
+ && [[dbs objectForKey:currentDb] objectForKey:[NSString stringWithFormat:@"%@%@%@", currentDb, SPUniqueSchemaDelimiter, [uniqueSchema objectAtIndex:1]]] )
+ {
aTableNameExists = YES;
aTableName = [uniqueSchema objectAtIndex:1];
aTableName_id = [NSString stringWithFormat:@"%@%@%@", currentDb, SPUniqueSchemaDelimiter, aTableName];
@@ -379,7 +379,7 @@ NSInteger alphabeticSort(id string1, id string2, void *reverse)
}
// If no db name but table name check if table name is a valid db name
- if(!aTableNameExists && aTableName && [aTableName length] && uniqueSchemaKind == 1) {
+ if(uniqueSchemaKind == 1 && !aTableNameExists && aTableName && [aTableName length]) {
aDbName_id = [NSString stringWithFormat:@"%@%@%@", connectionID, SPUniqueSchemaDelimiter, [uniqueSchema objectAtIndex:1]];
aTableNameExists = NO;
}
@@ -766,7 +766,7 @@ NSInteger alphabeticSort(id string1, id string2, void *reverse)
object:nil];
// Check for table name aliases
- if(tableDocumentInstance && customQueryInstance) {
+ if(dbBrowseMode && tableDocumentInstance && customQueryInstance) {
NSString *theDb = (dbName == nil) ? [NSString stringWithString:currentDb] : [NSString stringWithString:dbName];
NSString *connectionID = [tableDocumentInstance connectionID];
NSString *conID = [NSString stringWithFormat:@"%@%@%@", connectionID, SPUniqueSchemaDelimiter, theDb];