aboutsummaryrefslogtreecommitdiffstats
path: root/Source/SPIndexesController.m
diff options
context:
space:
mode:
authorstuconnolly <stuart02@gmail.com>2010-12-27 21:02:13 +0000
committerstuconnolly <stuart02@gmail.com>2010-12-27 21:02:13 +0000
commit79743cca20cc056ef9f24ca664557e55e7d34cc2 (patch)
tree2b290d905e097fb96ef975aebbcc306e703d9074 /Source/SPIndexesController.m
parenta8a48e6ebf8ff8a3a897e896d33ed21080039d40 (diff)
downloadsequelpro-79743cca20cc056ef9f24ca664557e55e7d34cc2.tar.gz
sequelpro-79743cca20cc056ef9f24ca664557e55e7d34cc2.tar.bz2
sequelpro-79743cca20cc056ef9f24ca664557e55e7d34cc2.zip
When opening the add index sheet, the initial suggested field should be one that is not already indexed. This completes the implementation of issue #928.
Diffstat (limited to 'Source/SPIndexesController.m')
-rw-r--r--Source/SPIndexesController.m24
1 files changed, 23 insertions, 1 deletions
diff --git a/Source/SPIndexesController.m b/Source/SPIndexesController.m
index f3661528..16d9b4f6 100644
--- a/Source/SPIndexesController.m
+++ b/Source/SPIndexesController.m
@@ -149,6 +149,7 @@ static const NSString *SPNewIndexKeyBlockSize = @"IndexKeyBlockSize";
{
if ([[index objectForKey:@"Key_name"] isEqualToString:@"PRIMARY"]) {
hasCompositePrimaryKey = YES;
+ break;
}
}
}
@@ -168,10 +169,31 @@ static const NSString *SPNewIndexKeyBlockSize = @"IndexKeyBlockSize";
break;
}
}
+
+ NSMutableArray *indexedFieldNames = [[NSMutableArray alloc] init];
+
+ // Build an array of all indexed column names
+ for (NSDictionary *index in indexes)
+ {
+ [indexedFieldNames addObject:[index objectForKey:@"Column_name"]];
+ }
+
+ NSDictionary *initialField = nil;
+
+ // Select the first column as the initial field that doesn't already have an index
+ for (NSDictionary *field in fields)
+ {
+ if (![indexedFieldNames containsObject:[field objectForKey:@"name"]]) {
+ initialField = [[field mutableCopy] autorelease];
+ break;
+ }
+ }
+
+ [indexedFieldNames release];
// Reset the indexed columns
[indexedFields removeAllObjects];
- [indexedFields addObject:[[[fields objectAtIndex:0] mutableCopy] autorelease]];
+ [indexedFields addObject:initialField];
[indexedColumnsTableView reloadData];