aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Interfaces/English.lproj/DBView.xib51
-rw-r--r--Source/SPTableStructure.h2
-rw-r--r--Source/SPTableStructure.m106
3 files changed, 104 insertions, 55 deletions
diff --git a/Interfaces/English.lproj/DBView.xib b/Interfaces/English.lproj/DBView.xib
index e5b93be2..da65886c 100644
--- a/Interfaces/English.lproj/DBView.xib
+++ b/Interfaces/English.lproj/DBView.xib
@@ -23,7 +23,7 @@
</object>
<object class="NSMutableArray" key="IBDocument.EditedObjectIDs">
<bool key="EncodedWithXMLCoder">YES</bool>
- <integer value="7484"/>
+ <integer value="1304"/>
</object>
<object class="NSArray" key="IBDocument.PluginDependencies">
<bool key="EncodedWithXMLCoder">YES</bool>
@@ -1069,41 +1069,9 @@
<reference key="NSTextColor" ref="454249633"/>
<int key="NSVisibleItemCount">10</int>
<bool key="NSHasVerticalScroller">YES</bool>
+ <bool key="NSUsesDataSource">YES</bool>
<bool key="NSCompletes">YES</bool>
- <object class="NSMutableArray" key="NSPopUpListData">
- <bool key="EncodedWithXMLCoder">YES</bool>
- <string>TINYINT</string>
- <string>SMALLINT</string>
- <string>MEDIUMINT</string>
- <string>INT</string>
- <string>BIGINT</string>
- <string>FLOAT</string>
- <string>DOUBLE</string>
- <string>DECIMAL</string>
- <string>--------</string>
- <string>DATE</string>
- <string>DATETIME</string>
- <string>TIMESTAMP</string>
- <string>TIME</string>
- <string>YEAR</string>
- <string>--------</string>
- <string>CHAR</string>
- <string>VARCHAR</string>
- <string>TINYBLOB</string>
- <string>TINYTEXT</string>
- <string>BLOB</string>
- <string>TEXT</string>
- <string>MEDIUMBLOB</string>
- <string>MEDIUMTEXT</string>
- <string>LONGBLOB</string>
- <string>LONGTEXT</string>
- <string>ENUM</string>
- <string>SET</string>
- <string>--------</string>
- <string>BIT</string>
- <string>BINARY</string>
- <string>VARBINARY</string>
- </object>
+ <nil key="NSDataSource"/>
<object class="NSComboTableView" key="NSTableView" id="567127181">
<reference key="NSNextResponder"/>
<int key="NSvFlags">274</int>
@@ -1148,7 +1116,6 @@
<string key="NSAction">tableViewAction:</string>
<int key="NSTvFlags">-228556800</int>
<reference key="NSDelegate" ref="904218650"/>
- <reference key="NSDataSource" ref="904218650"/>
<reference key="NSTarget" ref="904218650"/>
<int key="NSColumnAutoresizingStyle">1</int>
<int key="NSDraggingSourceMaskForLocal">15</int>
@@ -14756,6 +14723,14 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8</string>
</object>
<int key="connectionID">7496</int>
</object>
+ <object class="IBConnectionRecord">
+ <object class="IBOutletConnection" key="connection">
+ <string key="label">dataSource</string>
+ <reference key="source" ref="904218650"/>
+ <reference key="destination" ref="103234030"/>
+ </object>
+ <int key="connectionID">7498</int>
+ </object>
</object>
<object class="IBMutableOrderedSet" key="objectRecords">
<object class="NSArray" key="orderedObjects">
@@ -23314,7 +23289,7 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
- <string>{{-19, 172}, {943, 549}}</string>
+ <string>{{0, 172}, {943, 549}}</string>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
<boolean value="YES"/>
<string>com.apple.InterfaceBuilder.CocoaPlugin</string>
@@ -23665,7 +23640,7 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8</string>
</object>
</object>
<nil key="sourceID"/>
- <int key="maxID">7497</int>
+ <int key="maxID">7498</int>
</object>
<object class="IBClassDescriber" key="IBDocument.Classes">
<object class="NSMutableArray" key="referencedPartialClassDescriptions">
diff --git a/Source/SPTableStructure.h b/Source/SPTableStructure.h
index 0be1082b..6af0a3b3 100644
--- a/Source/SPTableStructure.h
+++ b/Source/SPTableStructure.h
@@ -70,6 +70,8 @@
NSInteger currentlyEditingRow;
NSUserDefaults *prefs;
NSArray *collations;
+ NSArray *typeSuggestions;
+
}
// Table methods
diff --git a/Source/SPTableStructure.m b/Source/SPTableStructure.m
index 1d05ba7f..48b3cf22 100644
--- a/Source/SPTableStructure.m
+++ b/Source/SPTableStructure.m
@@ -55,6 +55,7 @@
tableFields = [[NSMutableArray alloc] init];
oldRow = [[NSMutableDictionary alloc] init];
enumFields = [[NSMutableDictionary alloc] init];
+ typeSuggestions = nil;
currentlyEditingRow = -1;
defaultValues = nil;
@@ -75,12 +76,43 @@
[tableSourceView setGridStyleMask:([prefs boolForKey:SPDisplayTableViewVerticalGridlines]) ? NSTableViewSolidVerticalGridLineMask : NSTableViewGridNone];
// Set the strutcture and index view's font
- BOOL useMonospacedFont = [prefs boolForKey:SPUseMonospacedFonts];
-
- for (NSTableColumn *fieldColumn in [tableSourceView tableColumns])
- {
- [[fieldColumn dataCell] setFont:(useMonospacedFont) ? [NSFont fontWithName:SPDefaultMonospacedFontName size:[NSFont smallSystemFontSize]] : [NSFont systemFontOfSize:[NSFont smallSystemFontSize]]];
- }
+ [tableSourceView setFont:([prefs boolForKey:SPUseMonospacedFonts]) ? [NSFont fontWithName:SPDefaultMonospacedFontName size:[NSFont smallSystemFontSize]] : [NSFont systemFontOfSize:[NSFont smallSystemFontSize]]];
+
+ typeSuggestions = [[NSArray arrayWithObjects:
+ @"TINYINT",
+ @"SMALLINT",
+ @"MEDIUMINT",
+ @"INT",
+ @"BIGINT",
+ @"FLOAT",
+ @"DOUBLE",
+ @"DOUBLE PRECISION",
+ @"REAL",
+ @"DECIMAL",
+ @"BIT",
+ @"--------",
+ @"CHAR",
+ @"VARCHAR",
+ @"BINARY",
+ @"VARBINARY",
+ @"TINYBLOB",
+ @"BLOB",
+ @"TEXT",
+ @"MEDIUMBLOB",
+ @"MEDIUMTEXT",
+ @"LONGBLOB",
+ @"LONGTEXT",
+ @"ENUM",
+ @"SET",
+ @"--------",
+ @"DATE",
+ @"DATETIME",
+ @"TIMESTAMP",
+ @"TIME",
+ @"YEAR",
+ nil] retain];
+ // Hint: in [self addRowToDB] > [typeSuggestions indexOfObject:theRowType] < 11 etc. has to be changed if typeSuggestions was changed!
+
databaseDataInstance = [tableDocumentInstance valueForKeyPath:@"databaseDataInstance"];
@@ -681,6 +713,7 @@ closes the keySheet
NSInteger code;
NSDictionary *theRow;
NSMutableString *queryString;
+ NSString *theRowType;
if (!isEditingRow || currentlyEditingRow == -1)
return YES;
@@ -690,6 +723,8 @@ closes the keySheet
theRow = [tableFields objectAtIndex:currentlyEditingRow];
+ theRowType = [[theRow objectForKey:@"type"] uppercaseString];
+
if (isEditingNewRow) {
// ADD syntax
if ([[theRow objectForKey:@"length"] isEqualToString:@""] || ![theRow objectForKey:@"length"]) {
@@ -697,13 +732,13 @@ closes the keySheet
queryString = [NSMutableString stringWithFormat:@"ALTER TABLE %@ ADD %@ %@",
[selectedTable backtickQuotedString],
[[theRow objectForKey:@"name"] backtickQuotedString],
- [[theRow objectForKey:@"type"] uppercaseString]];
+ theRowType];
}
else {
queryString = [NSMutableString stringWithFormat:@"ALTER TABLE %@ ADD %@ %@(%@)",
[selectedTable backtickQuotedString],
[[theRow objectForKey:@"name"] backtickQuotedString],
- [[theRow objectForKey:@"type"] uppercaseString],
+ theRowType,
[theRow objectForKey:@"length"]];
}
}
@@ -724,7 +759,7 @@ closes the keySheet
[selectedTable backtickQuotedString],
[[oldRow objectForKey:@"name"] backtickQuotedString],
[[theRow objectForKey:@"name"] backtickQuotedString],
- [[theRow objectForKey:@"type"] uppercaseString]];
+ theRowType];
}
else {
// If the old row and new row dictionaries are equal then the user didn't actually change anything so don't continue
@@ -738,7 +773,7 @@ closes the keySheet
[selectedTable backtickQuotedString],
[[oldRow objectForKey:@"name"] backtickQuotedString],
[[theRow objectForKey:@"name"] backtickQuotedString],
- [[theRow objectForKey:@"type"] uppercaseString],
+ theRowType,
[theRow objectForKey:@"length"]];
}
}
@@ -791,7 +826,7 @@ closes the keySheet
}
}
// Otherwise, if CURRENT_TIMESTAMP was specified for timestamps, use that
- else if ([[theRow objectForKey:@"type"] isEqualToString:@"timestamp"] &&
+ else if ([theRowType isEqualToString:@"TIMESTAMP"] &&
[[[theRow objectForKey:@"default"] uppercaseString] isEqualToString:@"CURRENT_TIMESTAMP"])
{
[queryString appendString:@" DEFAULT CURRENT_TIMESTAMP "];
@@ -799,9 +834,14 @@ closes the keySheet
}
// If the field is of type BIT, permit the use of single qoutes and also don't quote the default value.
// For example, use DEFAULT b'1' as opposed to DEFAULT 'b\'1\'' which results in an error.
- else if ([[[theRow objectForKey:@"type"] lowercaseString] isEqualToString:@"bit"]) {
+ else if ([[theRow objectForKey:@"default"] length] && [theRowType isEqualToString:@"BIT"]) {
[queryString appendFormat:@" DEFAULT %@ ", [theRow objectForKey:@"default"]];
}
+ // Suppress appending DEFAULT clause for any numerics, date, time fields if default is empty to avoid error messages
+ // Hint: [typeSuggestions indexOfObject:theRowType] < 11 has to be changed if typeSuggestions was changed!
+ else if (![[theRow objectForKey:@"default"] length] && ([typeSuggestions indexOfObject:theRowType] < 11 || [typeSuggestions indexOfObject:theRowType] > 25)) {
+ ;
+ }
// Otherwise, use the provided default
else {
[queryString appendFormat:@" DEFAULT '%@' ", [mySQLConnection prepareString:[theRow objectForKey:@"default"]]];
@@ -818,12 +858,12 @@ closes the keySheet
[queryString appendString:[theRow objectForKey:@"Extra"]];
}
- if (!isEditingNewRow) {
+ // Any column comments
+ if ([[theRow objectForKey:@"comment"] length]) {
+ [queryString appendFormat:@" COMMENT '%@'", [mySQLConnection prepareString:[theRow objectForKey:@"comment"]]];
+ }
- // Any column comments
- if ([[theRow objectForKey:@"comment"] length]) {
- [queryString appendFormat:@" COMMENT '%@'", [mySQLConnection prepareString:[theRow objectForKey:@"comment"]]];
- }
+ if (!isEditingNewRow) {
// Unparsed details - column formats, storage, reference definitions
if ([[theRow objectForKey:@"unparsed"] length]) {
@@ -1674,6 +1714,37 @@ would result in a position change.
}
#pragma mark -
+#pragma mark NSComboBox delegates
+
+- (id)comboBoxCell:(NSComboBoxCell *)aComboBoxCell objectValueForItemAtIndex:(NSInteger)index
+{
+ return [typeSuggestions objectAtIndex:index];
+}
+
+- (NSInteger)numberOfItemsInComboBoxCell:(NSComboBoxCell *)aComboBoxCell
+{
+ return [typeSuggestions count];
+}
+
+/**
+ * Allow completion for lowercased input
+ */
+- (NSString *)comboBoxCell:(NSComboBoxCell *)aComboBoxCell completedString:(NSString *)uncompletedString
+{
+
+ if([uncompletedString hasPrefix:@"-"]) return @"";
+
+ NSPredicate *predicate = [NSPredicate predicateWithFormat:@"SELF BEGINSWITH[c] %@", [uncompletedString uppercaseString]];
+ NSArray *result = [typeSuggestions filteredArrayUsingPredicate:predicate];
+
+ if(result && [result count])
+ return [result objectAtIndex:0];
+
+ return @"";
+
+}
+
+#pragma mark -
#pragma mark Private API methods
/**
@@ -1751,6 +1822,7 @@ would result in a position change.
[tableFields release];
[oldRow release];
[enumFields release];
+ [typeSuggestions release];
if (defaultValues) [defaultValues release];
if (selectedTable) [selectedTable release];