aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBibiko <bibiko@eva.mpg.de>2010-11-01 11:04:01 +0000
committerBibiko <bibiko@eva.mpg.de>2010-11-01 11:04:01 +0000
commit7587849d307c6c0a7fa11ddbc2ee48af87ab9087 (patch)
tree3ae2092799de52002d553baa463a0c04878439f1
parenta6325dbb88629e7bc5e170bb23955ebf1910c17b (diff)
downloadsequelpro-7587849d307c6c0a7fa11ddbc2ee48af87ab9087.tar.gz
sequelpro-7587849d307c6c0a7fa11ddbc2ee48af87ab9087.tar.bz2
sequelpro-7587849d307c6c0a7fa11ddbc2ee48af87ab9087.zip
• improved Structure editing logic to allow to choose auto_increment for Extra only if table has no auto_increment field set since MySQL allows only one auto column
- the user has still the chance to type 'auto_increment' into the Extra manually
-rw-r--r--Interfaces/English.lproj/DBView.xib25
-rw-r--r--Source/SPTableData.h3
-rw-r--r--Source/SPTableData.m8
-rw-r--r--Source/SPTableStructure.h4
-rw-r--r--Source/SPTableStructure.m20
-rw-r--r--Source/SPTableStructureDelegate.m27
6 files changed, 64 insertions, 23 deletions
diff --git a/Interfaces/English.lproj/DBView.xib b/Interfaces/English.lproj/DBView.xib
index c2ad3857..a17ee340 100644
--- a/Interfaces/English.lproj/DBView.xib
+++ b/Interfaces/English.lproj/DBView.xib
@@ -3,7 +3,7 @@
<data>
<int key="IBDocument.SystemTarget">1050</int>
<string key="IBDocument.SystemVersion">10F569</string>
- <string key="IBDocument.InterfaceBuilderVersion">823</string>
+ <string key="IBDocument.InterfaceBuilderVersion">788</string>
<string key="IBDocument.AppKitVersion">1038.29</string>
<string key="IBDocument.HIToolboxVersion">461.00</string>
<object class="NSMutableDictionary" key="IBDocument.PluginVersions">
@@ -16,15 +16,15 @@
</object>
<object class="NSMutableArray" key="dict.values">
<bool key="EncodedWithXMLCoder">YES</bool>
- <string>823</string>
- <string>823</string>
+ <string>788</string>
+ <string>788</string>
<string>1.2.5</string>
</object>
</object>
<object class="NSMutableArray" key="IBDocument.EditedObjectIDs">
<bool key="EncodedWithXMLCoder">YES</bool>
<integer value="6735"/>
- <integer value="6701"/>
+ <integer value="1309"/>
</object>
<object class="NSArray" key="IBDocument.PluginDependencies">
<bool key="EncodedWithXMLCoder">YES</bool>
@@ -941,7 +941,7 @@
<object class="NSTabViewItem" id="831053945">
<string key="NSIdentifier">source</string>
<object class="NSView" key="NSView" id="461236772">
- <nil key="NSNextResponder"/>
+ <reference key="NSNextResponder" ref="714795046"/>
<int key="NSvFlags">256</int>
<object class="NSMutableArray" key="NSSubviews">
<bool key="EncodedWithXMLCoder">YES</bool>
@@ -1474,13 +1474,6 @@
<int key="NSVisibleItemCount">4</int>
<bool key="NSHasVerticalScroller">YES</bool>
<bool key="NSCompletes">YES</bool>
- <object class="NSMutableArray" key="NSPopUpListData">
- <bool key="EncodedWithXMLCoder">YES</bool>
- <string>None</string>
- <string>auto_increment</string>
- <string>on update CURRENT_TIMESTAMP</string>
- <string>SERIAL DEFAULT VALUE</string>
- </object>
<object class="NSComboTableView" key="NSTableView" id="1025423991">
<reference key="NSNextResponder"/>
<int key="NSvFlags">274</int>
@@ -2419,6 +2412,7 @@
</object>
</object>
<string key="NSFrame">{{10, 7}, {706, 544}}</string>
+ <reference key="NSSuperview" ref="714795046"/>
</object>
<string key="NSLabel">Structure</string>
<reference key="NSColor" ref="62854682"/>
@@ -5727,7 +5721,7 @@
<object class="NSTabViewItem" id="75945221">
<string key="NSIdentifier">triggers</string>
<object class="NSView" key="NSView" id="776303855">
- <reference key="NSNextResponder" ref="714795046"/>
+ <nil key="NSNextResponder"/>
<int key="NSvFlags">256</int>
<object class="NSMutableArray" key="NSSubviews">
<bool key="EncodedWithXMLCoder">YES</bool>
@@ -6160,21 +6154,20 @@
</object>
</object>
<string key="NSFrame">{{10, 7}, {706, 544}}</string>
- <reference key="NSSuperview" ref="714795046"/>
</object>
<string key="NSLabel">Triggers</string>
<reference key="NSColor" ref="62854682"/>
<reference key="NSTabView" ref="714795046"/>
</object>
</object>
- <reference key="NSSelectedTabViewItem" ref="75945221"/>
+ <reference key="NSSelectedTabViewItem" ref="831053945"/>
<reference key="NSFont" ref="26"/>
<int key="NSTvFlags">134217731</int>
<bool key="NSAllowTruncatedLabels">YES</bool>
<bool key="NSDrawsBackground">YES</bool>
<object class="NSMutableArray" key="NSSubviews">
<bool key="EncodedWithXMLCoder">YES</bool>
- <reference ref="776303855"/>
+ <reference ref="461236772"/>
</object>
</object>
</object>
diff --git a/Source/SPTableData.h b/Source/SPTableData.h
index b978acc4..cb24d51f 100644
--- a/Source/SPTableData.h
+++ b/Source/SPTableData.h
@@ -42,9 +42,12 @@
MCPConnection *mySQLConnection;
BOOL isWorking;
+ BOOL tableHasAutoIncrementField;
+
}
@property (readwrite, assign) BOOL isWorking;
+@property (readonly, assign) BOOL tableHasAutoIncrementField;
- (void) setConnection:(MCPConnection *)theConnection;
- (NSString *) tableEncoding;
diff --git a/Source/SPTableData.m b/Source/SPTableData.m
index e39635c7..404395b9 100644
--- a/Source/SPTableData.m
+++ b/Source/SPTableData.m
@@ -34,6 +34,8 @@
@implementation SPTableData
@synthesize isWorking;
+@synthesize tableHasAutoIncrementField;
+;
/**
* Init class.
@@ -51,6 +53,8 @@
tableCreateSyntax = nil;
mySQLConnection = nil;
isWorking = NO;
+ tableHasAutoIncrementField = NO;
+
}
return self;
@@ -385,6 +389,7 @@
[columns removeAllObjects];
[columnNames removeAllObjects];
[constraints removeAllObjects];
+ tableHasAutoIncrementField = NO;
if( [tableListInstance tableType] == SPTableTypeTable || [tableListInstance tableType] == SPTableTypeView ) {
tableData = [self informationForTable:[tableListInstance tableName]];
@@ -425,6 +430,8 @@
NSDictionary *columnData;
NSEnumerator *enumerator;
+ tableHasAutoIncrementField = NO;
+
if (viewData == nil) {
[columns removeAllObjects];
[columnNames removeAllObjects];
@@ -1244,6 +1251,7 @@
// Whether fields should auto-increment
} else if ([detailString isEqualToString:@"AUTO_INCREMENT"]) {
[fieldDetails setValue:boolYES forKey:@"autoincrement"];
+ tableHasAutoIncrementField = YES;
// Field defaults
} else if ([detailString isEqualToString:@"DEFAULT"] && (definitionPartsIndex + 1 < partsArrayLength)) {
diff --git a/Source/SPTableStructure.h b/Source/SPTableStructure.h
index 1ae392f4..fe13b944 100644
--- a/Source/SPTableStructure.h
+++ b/Source/SPTableStructure.h
@@ -58,7 +58,7 @@
IBOutlet id viewColumnsMenu;
IBOutlet id encodingPopupCell;
-
+
MCPConnection *mySQLConnection;
MCPResult *tableSourceResult;
MCPResult *indexResult;
@@ -73,6 +73,8 @@
NSUserDefaults *prefs;
NSArray *collations;
NSArray *typeSuggestions;
+ NSArray *extraFieldSuggestions;
+ BOOL isCurrentExtraAutoIncrement;
BOOL isEditingRow, isEditingNewRow, isSavingRow, alertSheetOpened;
}
diff --git a/Source/SPTableStructure.m b/Source/SPTableStructure.m
index 14ae632c..2392c108 100644
--- a/Source/SPTableStructure.m
+++ b/Source/SPTableStructure.m
@@ -58,7 +58,9 @@
defaultValues = nil;
selectedTable = nil;
typeSuggestions = nil;
+ extraFieldSuggestions = nil;
currentlyEditingRow = -1;
+ isCurrentExtraAutoIncrement = NO;
fieldValidation = [[SPTableFieldValidation alloc] init];
@@ -80,6 +82,14 @@
[tableSourceView setFont:([prefs boolForKey:SPUseMonospacedFonts]) ? [NSFont fontWithName:SPDefaultMonospacedFontName size:[NSFont smallSystemFontSize]] : [NSFont systemFontOfSize:[NSFont smallSystemFontSize]]];
[indexesTableView setFont:([prefs boolForKey:SPUseMonospacedFonts]) ? [NSFont fontWithName:SPDefaultMonospacedFontName size:[NSFont smallSystemFontSize]] : [NSFont systemFontOfSize:[NSFont smallSystemFontSize]]];
+ extraFieldSuggestions = [[NSArray arrayWithObjects:
+ @"None",
+ @"auto_increment",
+ @"on update CURRENT_TIMESTAMP",
+ @"SERIAL DEFAULT VALUE",
+ nil
+ ] retain];
+
// Note that changing the contents or ordering of this array will affect the implementation of
// SPTableFieldValidation. See it's implementation file for more details.
typeSuggestions = [[NSArray arrayWithObjects:
@@ -326,6 +336,8 @@
nil];
[[self onMainThread] setTableDetails:tableDetails];
+ isCurrentExtraAutoIncrement = [tableDataInstance tableHasAutoIncrementField];
+
// Send the query finished/work complete notification
[[NSNotificationCenter defaultCenter] postNotificationOnMainThreadWithName:@"SMySQLQueryHasBeenPerformed" object:tableDocumentInstance];
@@ -705,6 +717,7 @@
[tableFields replaceObjectAtIndex:currentlyEditingRow withObject:[NSMutableDictionary dictionaryWithDictionary:oldRow]];
}
isEditingRow = NO;
+ isCurrentExtraAutoIncrement = [tableDataInstance tableHasAutoIncrementField];
[tableSourceView reloadData];
currentlyEditingRow = -1;
[[tableDocumentInstance parentWindow] makeFirstResponder:tableSourceView];
@@ -1092,7 +1105,9 @@
else if (isEditingNewRow) {
[queryString appendFormat:@"\n AFTER %@", [[[tableFields objectAtIndex:(currentlyEditingRow -1)] objectForKey:@"name"] backtickQuotedString]];
}
-
+
+ isCurrentExtraAutoIncrement = NO;
+
// Execute query
[mySQLConnection queryString:queryString];
@@ -1543,7 +1558,8 @@
[oldRow release];
[enumFields release];
[typeSuggestions release];
-
+ [extraFieldSuggestions release];
+
[fieldValidation release], fieldValidation = nil;
if (defaultValues) [defaultValues release];
diff --git a/Source/SPTableStructureDelegate.m b/Source/SPTableStructureDelegate.m
index b3246ca2..bdc3cb3f 100644
--- a/Source/SPTableStructureDelegate.m
+++ b/Source/SPTableStructureDelegate.m
@@ -65,7 +65,18 @@
[[tableColumn dataCell] addItemWithTitle:[collation objectForKey:@"COLLATION_NAME"]];
}
}
-
+
+ else if([[tableColumn identifier] isEqualToString:@"Extra"]) {
+ id dataCell = [tableColumn dataCell];
+ [dataCell removeAllItems];
+ // Populate Extra suggestion popup button
+ for (id item in extraFieldSuggestions) {
+ if(!(isCurrentExtraAutoIncrement && [item isEqualToString:@"auto_increment"])) {
+ [dataCell addItemWithObjectValue:item];
+ }
+ }
+ }
+
return [NSArrayObjectAtIndex(tableFields, rowIndex) objectForKey:[tableColumn identifier]];
}
@@ -98,13 +109,21 @@
[tableSourceView reloadData];
}
}
- // Reset collation if BINARY was set to 1 since BINARY sets collation to *_bin
+ // Set null field to "do not allow NULL" for auto_increment Extra and reset Extra suggestion list
else if([[aTableColumn identifier] isEqualToString:@"Extra"]) {
if(![[currentRow objectForKey:@"Extra"] isEqualToString:anObject]) {
- if([[[currentRow objectForKey:@"Extra"] uppercaseString] isEqualToString:@"AUTO_INCREMENT"]) {
+
+ isCurrentExtraAutoIncrement = [[[anObject stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]] uppercaseString] isEqualToString:@"AUTO_INCREMENT"];
+ if(isCurrentExtraAutoIncrement)
[currentRow setObject:[NSNumber numberWithInteger:0] forKey:@"null"];
- }
+
+ id dataCell = [aTableColumn dataCell];
+ [dataCell removeAllItems];
+ [dataCell addItemsWithObjectValues:extraFieldSuggestions];
+ [dataCell noteNumberOfItemsChanged];
+ [dataCell reloadData];
[tableSourceView reloadData];
+
}
}
// Reset default to "" if field doesn't allow NULL and current default is set to NULL