aboutsummaryrefslogtreecommitdiffstats
path: root/Source/TableContent.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/TableContent.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/TableContent.m')
-rw-r--r--Source/TableContent.m11
1 files changed, 7 insertions, 4 deletions
diff --git a/Source/TableContent.m b/Source/TableContent.m
index 26d2138e..f8b29c28 100644
--- a/Source/TableContent.m
+++ b/Source/TableContent.m
@@ -254,10 +254,13 @@
// Retrieve the constraints, and loop through them to add up to one foreign key to each column
NSArray *constraints = [tableDataInstance getConstraints];
- for (NSDictionary *constraint in constraints) {
- NSString *firstColumn = [[[constraint objectForKey:@"columns"] componentsSeparatedByString:@","] objectAtIndex:0];
+
+ for (NSDictionary *constraint in constraints)
+ {
+ NSString *firstColumn = [[constraint objectForKey:@"columns"] objectAtIndex:0];
NSString *firstRefColumn = [[[constraint objectForKey:@"ref_columns"] componentsSeparatedByString:@","] objectAtIndex:0];
- NSUInteger columnIndex = [columnNames indexOfObject:firstColumn];
+ NSUInteger columnIndex = [columnNames indexOfObject:firstColumn];
+
if (columnIndex != NSNotFound && ![[dataColumns objectAtIndex:columnIndex] objectForKey:@"foreignkeyreference"]) {
NSDictionary *refDictionary = [NSDictionary dictionaryWithObjectsAndKeys:
[constraint objectForKey:@"ref_table"], @"table",
@@ -282,7 +285,7 @@
// Add the new columns to the table
for ( i = 0 ; i < [dataColumns count] ; i++ ) {
columnDefinition = NSArrayObjectAtIndex(dataColumns, i);
-
+
// Set up the column
theCol = [[NSTableColumn alloc] initWithIdentifier:[columnDefinition objectForKey:@"datacolumnindex"]];
[[theCol headerCell] setStringValue:[columnDefinition objectForKey:@"name"]];