diff options
author | stuconnolly <stuart02@gmail.com> | 2013-10-21 14:43:10 +0000 |
---|---|---|
committer | stuconnolly <stuart02@gmail.com> | 2013-10-21 14:43:10 +0000 |
commit | 546f436290721d208381769bef646a8ab9d42212 (patch) | |
tree | 6c49bf30c7c0328c6f8ff8a42ef6d06f132a4e52 /Source | |
parent | 43271f8e86b54c7d953c0e1c4059a2530693eb39 (diff) | |
download | sequelpro-546f436290721d208381769bef646a8ab9d42212.tar.gz sequelpro-546f436290721d208381769bef646a8ab9d42212.tar.bz2 sequelpro-546f436290721d208381769bef646a8ab9d42212.zip |
Issue #1369: Fix the display of cross database relations.
Diffstat (limited to 'Source')
-rw-r--r-- | Source/SPTableData.m | 14 | ||||
-rw-r--r-- | Source/SPTableRelations.m | 17 |
2 files changed, 22 insertions, 9 deletions
diff --git a/Source/SPTableData.m b/Source/SPTableData.m index 03ce039e..ac11c571 100644 --- a/Source/SPTableData.m +++ b/Source/SPTableData.m @@ -642,8 +642,18 @@ [constraintDetails setObject:keyColumns forKey:@"columns"]; - [fieldsParser setString:[[parts objectAtIndex:6] stringByTrimmingCharactersInSet:bracketSet]]; - [constraintDetails setObject:[fieldsParser unquotedString] forKey:@"ref_table"]; + NSString *part = [[parts objectAtIndex:6] stringByTrimmingCharactersInSet:bracketSet]; + + NSArray *reference = [part captureComponentsMatchedByRegex:@"^`([\\w_.]+)`\\.`([\\w_.]+)`$" options:RKLCaseless range:NSMakeRange(0, [part length]) error:nil]; + + if ([reference count]) { + [constraintDetails setObject:[reference objectAtIndex:1] forKey:@"ref_database"]; + [constraintDetails setObject:[reference objectAtIndex:2] forKey:@"ref_table"]; + } + else { + [fieldsParser setString:part]; + [constraintDetails setObject:[fieldsParser unquotedString] forKey:@"ref_table"]; + } NSMutableArray *refKeyColumns = [NSMutableArray array]; NSArray *refKeyColumnStrings = [[[parts objectAtIndex:7] stringByTrimmingCharactersInSet:bracketSet] componentsSeparatedByString:@","]; diff --git a/Source/SPTableRelations.m b/Source/SPTableRelations.m index 26ab8195..a28462b7 100644 --- a/Source/SPTableRelations.m +++ b/Source/SPTableRelations.m @@ -42,12 +42,13 @@ static NSString *SPRemoveRelation = @"SPRemoveRelation"; -static NSString *SPRelationNameKey = @"name"; -static NSString *SPRelationColumnsKey = @"columns"; -static NSString *SPRelationFKTableKey = @"fk_table"; -static NSString *SPRelationFKColumnsKey = @"fk_columns"; -static NSString *SPRelationOnUpdateKey = @"on_update"; -static NSString *SPRelationOnDeleteKey = @"on_delete"; +static NSString *SPRelationNameKey = @"name"; +static NSString *SPRelationColumnsKey = @"columns"; +static NSString *SPRelationFKDatabaseKey = @"fk_database"; +static NSString *SPRelationFKTableKey = @"fk_table"; +static NSString *SPRelationFKColumnsKey = @"fk_columns"; +static NSString *SPRelationOnUpdateKey = @"on_update"; +static NSString *SPRelationOnDeleteKey = @"on_delete"; @interface SPTableRelations () @@ -586,15 +587,17 @@ static NSString *SPRelationOnDeleteKey = @"on_delete"; NSArray *constraints = [tableDataInstance getConstraints]; for (NSDictionary *constraint in constraints) - { + { [relationData addObject:[NSDictionary dictionaryWithObjectsAndKeys: [constraint objectForKey:SPRelationNameKey], SPRelationNameKey, [[constraint objectForKey:SPRelationColumnsKey] componentsJoinedByCommas], SPRelationColumnsKey, + [constraint objectForKey:@"ref_database"] ? [constraint objectForKey:@"ref_database"] : [tableDocumentInstance database], SPRelationFKDatabaseKey, [constraint objectForKey:@"ref_table"], SPRelationFKTableKey, [[constraint objectForKey:@"ref_columns"] componentsJoinedByCommas], SPRelationFKColumnsKey, ([constraint objectForKey:@"update"] ? [constraint objectForKey:@"update"] : @""), SPRelationOnUpdateKey, ([constraint objectForKey:@"delete"] ? [constraint objectForKey:@"delete"] : @""), SPRelationOnDeleteKey, nil]]; + [takenConstraintNames addObject:[[constraint objectForKey:SPRelationNameKey] lowercaseString]]; } } |