aboutsummaryrefslogtreecommitdiffstats
path: root/Source/SPTextView.m
diff options
context:
space:
mode:
authorBibiko <bibiko@eva.mpg.de>2010-11-04 17:28:16 +0000
committerBibiko <bibiko@eva.mpg.de>2010-11-04 17:28:16 +0000
commit8f8694d3dec218bf85cc0f36eb6bc90b72ce9c6e (patch)
treec08613c27bd2acd4af6aa85a6e57947593998ec0 /Source/SPTextView.m
parent65670f060759c2d5f096db401390da47b9365706 (diff)
downloadsequelpro-8f8694d3dec218bf85cc0f36eb6bc90b72ce9c6e.tar.gz
sequelpro-8f8694d3dec218bf85cc0f36eb6bc90b72ce9c6e.tar.bz2
sequelpro-8f8694d3dec218bf85cc0f36eb6bc90b72ce9c6e.zip
• alias (auto-)completion
- further improvements regarding detecting of aliases esp. if used just after SELECT
Diffstat (limited to 'Source/SPTextView.m')
-rw-r--r--Source/SPTextView.m45
1 files changed, 25 insertions, 20 deletions
diff --git a/Source/SPTextView.m b/Source/SPTextView.m
index 892fc744..e9fe24a2 100644
--- a/Source/SPTextView.m
+++ b/Source/SPTextView.m
@@ -775,27 +775,32 @@ NSInteger alphabeticSort(id string1, id string2, void *reverse)
NSArray *allTables = [[dbs objectForKey:conID] allKeys];
// Check if found table name is known, if not parse for aliases
if(![allTables containsObject:[NSString stringWithFormat:@"%@%@%@", conID, SPUniqueSchemaDelimiter, tableName]]) {
- NSString* currentQuery = [[self string] substringWithRange:[customQueryInstance currentQueryRange]];
- NSRange aliasRange = [currentQuery rangeOfRegex:[NSString stringWithFormat:@"(?i)\\s`?(\\S+?)`?\\s+(AS\\s+)?`?%@`?\\b", tableName] capture:1L];
- if(aliasRange.length) {
- NSString *alias = [[currentQuery substringWithRange:aliasRange] stringByReplacingOccurrencesOfString:@"``" withString:@"`"];
- // If alias refers to db.table split it
- if([alias rangeOfString:@"."].length) {
- NSRange dbRange = [alias rangeOfRegex:@"^`?(.*?)`?\\." capture:1L];
- NSRange tbRange = [alias rangeOfRegex:@"\\.`?(.*?)`?$" capture:1L];
- NSString *db = [[alias substringWithRange:dbRange] stringByReplacingOccurrencesOfString:@"``" withString:@"`"];
- NSString *tb = [[alias substringWithRange:tbRange] stringByReplacingOccurrencesOfString:@"``" withString:@"`"];
- conID = [NSString stringWithFormat:@"%@%@%@", connectionID, SPUniqueSchemaDelimiter, db];
- if([dbs objectForKey:conID] && [[dbs objectForKey:conID] isKindOfClass:[NSDictionary class]]) {
- allTables = [[dbs objectForKey:conID] allKeys];
- if([allTables containsObject:[NSString stringWithFormat:@"%@%@%@", conID, SPUniqueSchemaDelimiter, tb]]) {
- tableName = tb;
- dbName = db;
+ NSString *currentQuery = [[self string] substringWithRange:[customQueryInstance currentQueryRange]];
+ NSArray *matches = [currentQuery componentsMatchedByRegex:[NSString stringWithFormat:@"(?i)\\s`?(\\S+?)`?\\s+(AS\\s+)?`?%@`?\\b", tableName]];
+ for(NSString* m in matches) {
+ NSRange aliasRange = [m rangeOfRegex:[NSString stringWithFormat:@"(?i)\\s`?(\\S+?)`?\\s+(AS\\s+)?`?%@`?\\b", tableName] capture:1L];
+ if(aliasRange.length) {
+ NSString *alias = [[m substringWithRange:aliasRange] stringByReplacingOccurrencesOfString:@"``" withString:@"`"];
+ // If alias refers to db.table split it
+ if([alias rangeOfString:@"."].length) {
+ NSRange dbRange = [alias rangeOfRegex:@"^`?(.*?)`?\\." capture:1L];
+ NSRange tbRange = [alias rangeOfRegex:@"\\.`?(.*?)`?$" capture:1L];
+ NSString *db = [[alias substringWithRange:dbRange] stringByReplacingOccurrencesOfString:@"``" withString:@"`"];
+ NSString *tb = [[alias substringWithRange:tbRange] stringByReplacingOccurrencesOfString:@"``" withString:@"`"];
+ conID = [NSString stringWithFormat:@"%@%@%@", connectionID, SPUniqueSchemaDelimiter, db];
+ if([dbs objectForKey:conID] && [[dbs objectForKey:conID] isKindOfClass:[NSDictionary class]]) {
+ allTables = [[dbs objectForKey:conID] allKeys];
+ if([allTables containsObject:[NSString stringWithFormat:@"%@%@%@", conID, SPUniqueSchemaDelimiter, tb]]) {
+ tableName = tb;
+ dbName = db;
+ break;
+ }
+ }
+ } else {
+ if([allTables containsObject:[NSString stringWithFormat:@"%@%@%@", conID, SPUniqueSchemaDelimiter, alias]]) {
+ tableName = alias;
+ break;
}
- }
- } else {
- if([allTables containsObject:[NSString stringWithFormat:@"%@%@%@", conID, SPUniqueSchemaDelimiter, alias]]) {
- tableName = alias;
}
}
}