aboutsummaryrefslogtreecommitdiffstats
path: root/Source/SPTableData.m
diff options
context:
space:
mode:
authorstuconnolly <stuart02@gmail.com>2009-11-18 22:20:25 +0000
committerstuconnolly <stuart02@gmail.com>2009-11-18 22:20:25 +0000
commita401277e6a7aff7ce778617d6c4de16f38e37fe5 (patch)
tree21eae12c0397be0b143c51b366ed24e4b93cdaf7 /Source/SPTableData.m
parentbf4a5566109942b94919d06f8a0edcacf68ceeb0 (diff)
downloadsequelpro-a401277e6a7aff7ce778617d6c4de16f38e37fe5.tar.gz
sequelpro-a401277e6a7aff7ce778617d6c4de16f38e37fe5.tar.bz2
sequelpro-a401277e6a7aff7ce778617d6c4de16f38e37fe5.zip
When attempting to delete a field that is part of a foreign key relationship, remove the key before the field to prevent an error. Obviously warn the user that the key is being dropped as well. Fixes issue #462.
This check also needs to be implemented when removing indexes as foreign keys depend on the presence of indexes to prevent table scans. Something to be discussed, the display of foreign keys that are made up of multiple fields in the relations table and link arrows in the content table.
Diffstat (limited to 'Source/SPTableData.m')
-rw-r--r--Source/SPTableData.m14
1 files changed, 11 insertions, 3 deletions
diff --git a/Source/SPTableData.m b/Source/SPTableData.m
index 0301fd41..c1fd0497 100644
--- a/Source/SPTableData.m
+++ b/Source/SPTableData.m
@@ -267,7 +267,7 @@
NSDictionary *columnData;
NSEnumerator *enumerator;
- if( [tableListInstance tableType] == SP_TABLETYPE_TABLE || [tableListInstance tableType] == SP_TABLETYPE_VIEW ) {
+ if( [tableListInstance tableType] == SP_TABLETYPE_TABLE || [tableListInstance tableType] == SP_TABLETYPE_VIEW ) {
tableData = [self informationForTable:[tableListInstance tableName]];
}
@@ -437,8 +437,16 @@
[fieldsParser setString:[[parts objectAtIndex:1] stringByTrimmingCharactersInSet:bracketSet]];
[constraintDetails setObject:[fieldsParser unquotedString] forKey:@"name"];
- [fieldsParser setString:[[parts objectAtIndex:4] stringByTrimmingCharactersInSet:bracketSet]];
- [constraintDetails setObject:[fieldsParser unquotedString] forKey:@"columns"];
+ NSMutableArray *keyColumns = [NSMutableArray array];
+ NSArray *keyColumnStrings = [[[parts objectAtIndex:4] stringByTrimmingCharactersInSet:bracketSet] componentsSeparatedByString:@","];
+
+ for (NSString *keyColumn in keyColumnStrings)
+ {
+ [fieldsParser setString:[[keyColumn stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceCharacterSet]] stringByTrimmingCharactersInSet:bracketSet]];
+ [keyColumns addObject:[fieldsParser unquotedString]];
+ }
+
+ [constraintDetails setObject:keyColumns forKey:@"columns"];
[fieldsParser setString:[[parts objectAtIndex:6] stringByTrimmingCharactersInSet:bracketSet]];
[constraintDetails setObject:[fieldsParser unquotedString] forKey:@"ref_table"];