aboutsummaryrefslogtreecommitdiffstats
path: root/Source
diff options
context:
space:
mode:
Diffstat (limited to 'Source')
-rw-r--r--Source/SPTableData.m14
-rw-r--r--Source/SPTableRelations.m17
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]];
}
}