From 79743cca20cc056ef9f24ca664557e55e7d34cc2 Mon Sep 17 00:00:00 2001 From: stuconnolly Date: Mon, 27 Dec 2010 21:02:13 +0000 Subject: 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. --- Source/SPIndexesController.m | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) (limited to 'Source') 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]; -- cgit v1.2.3