aboutsummaryrefslogtreecommitdiffstats
path: root/Source/SPIndexesController.m
diff options
context:
space:
mode:
authorstuconnolly <stuart02@gmail.com>2010-12-28 19:52:54 +0000
committerstuconnolly <stuart02@gmail.com>2010-12-28 19:52:54 +0000
commit37ef1ea26b8bd0e209f30474a53b9605ba8acfe6 (patch)
tree0432f1a449d64801f8d97dfda5faa48f8440b99f /Source/SPIndexesController.m
parente8bcfe72b6b59c8b881feff7ffdc8d719a82ff8c (diff)
parent16341191bcc112fcf18ddaed2d4755b11479ba45 (diff)
downloadsequelpro-37ef1ea26b8bd0e209f30474a53b9605ba8acfe6.tar.gz
sequelpro-37ef1ea26b8bd0e209f30474a53b9605ba8acfe6.tar.bz2
sequelpro-37ef1ea26b8bd0e209f30474a53b9605ba8acfe6.zip
Bring fravorites outline view branch up to date with trunk (r3036:3058).
Diffstat (limited to 'Source/SPIndexesController.m')
-rw-r--r--Source/SPIndexesController.m54
1 files changed, 47 insertions, 7 deletions
diff --git a/Source/SPIndexesController.m b/Source/SPIndexesController.m
index a19480e6..27b4471d 100644
--- a/Source/SPIndexesController.m
+++ b/Source/SPIndexesController.m
@@ -129,17 +129,32 @@ static const NSString *SPNewIndexKeyBlockSize = @"IndexKeyBlockSize";
[indexNameTextField setEnabled:NO];
[indexNameTextField setStringValue:@"PRIMARY"];
- // If the table is of type MyISAM and Spation extension support is available, add the SPATIAL type
+ // If the table is of type MyISAM and Spatial extension support is available, add the SPATIAL type
NSString *engine = [[tableData statusValues] objectForKey:@"Engine"];
if ([engine isEqualToString:@"MyISAM"] && [[dbDocument serverSupport] supportsSpatialExtensions]) {
[indexTypePopUpButton addItemWithTitle:@"SPATIAL"];
}
-
+
// Check to see whether a primary key already exists for the table, and if so select INDEX instead
for (NSDictionary *field in fields)
{
- if ([field objectForKey:@"isprimarykey"]) {
+ BOOL hasCompositePrimaryKey = NO;
+ BOOL isPrimaryKey = [field objectForKey:@"isprimarykey"];
+
+ // The 'isprimarykey' key of a field is only present for single column primary keys, not composite keys,
+ // so we need to check the indexes manually.
+ if (!isPrimaryKey) {
+ for (NSDictionary *index in indexes)
+ {
+ if ([[index objectForKey:@"Key_name"] isEqualToString:@"PRIMARY"]) {
+ hasCompositePrimaryKey = YES;
+ break;
+ }
+ }
+ }
+
+ if (isPrimaryKey || hasCompositePrimaryKey) {
// Remove primary key option
[indexTypePopUpButton removeItemAtIndex:0];
@@ -154,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;
+ }
+ }
+
+ if (initialField) [indexedFieldNames release], initialField = nil;
// Reset the indexed columns
[indexedFields removeAllObjects];
- [indexedFields addObject:[[[fields objectAtIndex:0] mutableCopy] autorelease]];
+ [indexedFields addObject:initialField];
[indexedColumnsTableView reloadData];
@@ -393,15 +429,19 @@ static const NSString *SPNewIndexKeyBlockSize = @"IndexKeyBlockSize";
*/
- (NSInteger)numberOfItemsInComboBoxCell:(NSComboBoxCell *)comboBoxCell
{
- return [fields count];
+ return ([fields count] - [indexedFields count]);
}
/**
* Returns the item to be displayed in the combo box cell as the supplied index.
*/
- (id)comboBoxCell:(NSComboBoxCell *)comboBoxCell objectValueForItemAtIndex:(NSInteger)index
-{
- return [[fields objectAtIndex:index] objectForKey:@"name"];
+{
+ NSMutableArray *availableFields = [fields mutableCopy];
+
+ [availableFields removeObjectsInArray:indexedFields];
+
+ return [[availableFields objectAtIndex:index] objectForKey:@"name"];
}
#pragma mark -