aboutsummaryrefslogtreecommitdiffstats
path: root/Source
diff options
context:
space:
mode:
authorstuconnolly <stuart02@gmail.com>2010-12-25 22:09:13 +0000
committerstuconnolly <stuart02@gmail.com>2010-12-25 22:09:13 +0000
commite4c9f4057bb950d15e101c3222d95325d3ca67e8 (patch)
treedd46823fb798a9cb2a9c44d5ed625b5cdc70dbb2 /Source
parent7c0e19ddea57a362e9ec6bbc22a2b57b97a758f4 (diff)
downloadsequelpro-e4c9f4057bb950d15e101c3222d95325d3ca67e8.tar.gz
sequelpro-e4c9f4057bb950d15e101c3222d95325d3ca67e8.tar.bz2
sequelpro-e4c9f4057bb950d15e101c3222d95325d3ca67e8.zip
When adding a new index, as well as checking for an existing primary key also check for a composite primary key. Part of issue #928.
Diffstat (limited to 'Source')
-rw-r--r--Source/SPIndexesController.m22
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"];
}