diff options
-rw-r--r-- | Source/SPIndexesController.m | 22 |
1 files changed, 18 insertions, 4 deletions
diff --git a/Source/SPIndexesController.m b/Source/SPIndexesController.m index a19480e6..6a7c6cb7 100644 --- a/Source/SPIndexesController.m +++ b/Source/SPIndexesController.m @@ -129,17 +129,31 @@ 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; + } + } + } + + if (isPrimaryKey || hasCompositePrimaryKey) { // Remove primary key option [indexTypePopUpButton removeItemAtIndex:0]; @@ -400,7 +414,7 @@ static const NSString *SPNewIndexKeyBlockSize = @"IndexKeyBlockSize"; * 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"]; } |