aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorstuconnolly <stuart02@gmail.com>2010-10-28 20:18:32 +0000
committerstuconnolly <stuart02@gmail.com>2010-10-28 20:18:32 +0000
commit886ee90ca1047fdef2c6bfd52ea28ffc0345aca4 (patch)
tree2dd9c8b694fe395c159e57f5c1b1338629bcb866
parentf48b5ba6410a5d449fad026e870e2c3e5e0fcf53 (diff)
downloadsequelpro-886ee90ca1047fdef2c6bfd52ea28ffc0345aca4.tar.gz
sequelpro-886ee90ca1047fdef2c6bfd52ea28ffc0345aca4.tar.bz2
sequelpro-886ee90ca1047fdef2c6bfd52ea28ffc0345aca4.zip
Tidy up SPTableStructure including moving all the private field type validation methods to their own class, SPTableFieldValidation.
-rw-r--r--Source/SPTableFieldValidation.h42
-rw-r--r--Source/SPTableFieldValidation.m142
-rw-r--r--Source/SPTableStructure.h6
-rw-r--r--Source/SPTableStructure.m285
-rw-r--r--Source/SPTableStructureDelegate.m14
-rw-r--r--sequel-pro.xcodeproj/project.pbxproj22
6 files changed, 330 insertions, 181 deletions
diff --git a/Source/SPTableFieldValidation.h b/Source/SPTableFieldValidation.h
new file mode 100644
index 00000000..b9d973dd
--- /dev/null
+++ b/Source/SPTableFieldValidation.h
@@ -0,0 +1,42 @@
+//
+// $Id$
+//
+// SPTableFieldValidation.h
+// sequel-pro
+//
+// Created by Stuart Connolly (stuconnolly.com) on October 28, 2010
+// Copyright (c) 2010 Stuart Connolly. All rights reserved.
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// More info at <http://code.google.com/p/sequel-pro/>
+
+@interface SPTableFieldValidation : NSObject
+{
+ NSArray *fieldTypes;
+}
+
+/**
+ * @property fieldTypes Field types array
+ */
+@property (readwrite, retain) NSArray *fieldTypes;
+
+- (BOOL)isFieldTypeNumeric:(NSString *)fieldType;
+- (BOOL)isFieldTypeDate:(NSString *)fieldType;
+- (BOOL)isFieldTypeGeometry:(NSString *)fieldType;
+- (BOOL)isFieldTypeString:(NSString *)fieldType;
+- (BOOL)isFieldTypeAllowBinary:(NSString *)fieldType;
+
+@end
diff --git a/Source/SPTableFieldValidation.m b/Source/SPTableFieldValidation.m
new file mode 100644
index 00000000..ceee9b3b
--- /dev/null
+++ b/Source/SPTableFieldValidation.m
@@ -0,0 +1,142 @@
+//
+// $Id$
+//
+// SPTableFieldValidation.m
+// sequel-pro
+//
+// Created by Stuart Connolly (stuconnolly.com) on October 28, 2010
+// Copyright (c) 2010 Stuart Connolly. All rights reserved.
+//
+// This program is free software; you can redistribute it and/or modify
+// it under the terms of the GNU General Public License as published by
+// the Free Software Foundation; either version 2 of the License, or
+// (at your option) any later version.
+//
+// This program is distributed in the hope that it will be useful,
+// but WITHOUT ANY WARRANTY; without even the implied warranty of
+// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+// GNU General Public License for more details.
+//
+// You should have received a copy of the GNU General Public License
+// along with this program; if not, write to the Free Software
+// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+//
+// More info at <http://code.google.com/p/sequel-pro/>
+
+#import "SPTableFieldValidation.h"
+
+@interface SPTableFieldValidation (PrivateAPI)
+
+- (NSString *)_formatType:(NSString *)type;
+
+@end
+
+@implementation SPTableFieldValidation
+
+@synthesize fieldTypes;
+
+#pragma mark -
+#pragma mark Public API
+
+/**
+ * Returns whether or not the supplied field type is numeric according to it's position within the currnet
+ * field types array.
+ *
+ * @param fieldType The field type to test
+ */
+- (BOOL)isFieldTypeNumeric:(NSString *)fieldType
+{
+ NSString *type = [self _formatType:fieldType];
+
+ if (![fieldTypes containsObject:type]) return YES;
+
+ return ([fieldTypes indexOfObject:type] < 17);
+}
+
+/**
+ * Returns whether or not the supplied field type is a date according to it's position within the currnet
+ * field types array.
+ *
+ * @param fieldType The field type to test
+ */
+- (BOOL)isFieldTypeDate:(NSString *)fieldType
+{
+ NSString *type = [self _formatType:fieldType];
+
+ if (![fieldTypes containsObject:type]) return YES;
+
+ return (([fieldTypes indexOfObject:type] > 32) && ([fieldTypes indexOfObject:type] < 38));
+}
+
+/**
+ * Returns whether or not the supplied field type is geometry according to it's position within the currnet
+ * field types array.
+ *
+ * @param fieldType The field type to test
+ */
+- (BOOL)isFieldTypeGeometry:(NSString *)fieldType
+{
+ NSString *type = [self _formatType:fieldType];
+
+ if (![fieldTypes containsObject:type]) return YES;
+
+ return ([fieldTypes indexOfObject:type] > 38);
+}
+
+/**
+ * Returns whether or not the supplied field type is a string according to it's position within the currnet
+ * field types array.
+ *
+ * @param fieldType The field type to test
+ */
+- (BOOL)isFieldTypeString:(NSString *)fieldType
+{
+ NSString *type = [self _formatType:fieldType];
+
+ if (![fieldTypes containsObject:type]) return YES;
+
+ return (([fieldTypes indexOfObject:type] > 17) && ([fieldTypes indexOfObject:type] < 32));
+}
+
+/**
+ * Returns whether or not the supplied field type allows binary according to it's position within the currnet
+ * field types array.
+ *
+ * @param fieldType The field type to test
+ */
+- (BOOL)isFieldTypeAllowBinary:(NSString *)fieldType
+{
+ NSString *type = [self _formatType:fieldType];
+
+ if (![fieldTypes containsObject:type]) return YES;
+
+ return (([fieldTypes indexOfObject:type] > 17) && ([fieldTypes indexOfObject:type] < 24));
+}
+
+#pragma mark -
+#pragma mark Private API
+
+/**
+ * Formats, i.e. removes whitespace and newlines as well as uppercases the supplied field type string.
+ *
+ * @param type The field type string to format
+ */
+- (NSString *)_formatType:(NSString *)type
+{
+ return [[type stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]] uppercaseString];
+}
+
+#pragma mark -
+#pragma mark Other
+
+/**
+ * Dealloc.
+ */
+- (void)dealloc
+{
+ [fieldTypes release], fieldTypes = nil;
+
+ [super dealloc];
+}
+
+@end
diff --git a/Source/SPTableStructure.h b/Source/SPTableStructure.h
index 68225fab..1ae392f4 100644
--- a/Source/SPTableStructure.h
+++ b/Source/SPTableStructure.h
@@ -25,6 +25,8 @@
#import <MCPKit/MCPKit.h>
+@class SPTableFieldValidation;
+
@interface SPTableStructure : NSObject
{
IBOutlet id tablesListInstance;
@@ -60,6 +62,8 @@
MCPConnection *mySQLConnection;
MCPResult *tableSourceResult;
MCPResult *indexResult;
+
+ SPTableFieldValidation *fieldValidation;
NSString *selectedTable;
NSMutableArray *tableFields;
@@ -100,7 +104,7 @@
- (BOOL)addRowToDB;
- (void)setAutoIncrementTo:(NSString*)valueAsString;
-// Getter methods
+// Accessors
- (NSString *)defaultValueForField:(NSString *)field;
- (NSArray *)fieldNames;
- (NSDictionary *)enumFields;
diff --git a/Source/SPTableStructure.m b/Source/SPTableStructure.m
index 86644319..14ae632c 100644
--- a/Source/SPTableStructure.m
+++ b/Source/SPTableStructure.m
@@ -36,11 +36,6 @@
@interface SPTableStructure (PrivateAPI)
- (void)_removeFieldAndForeignKey:(NSNumber *)removeForeignKey;
-- (BOOL)_isFieldTypeNumeric:(NSString*)aType;
-- (BOOL)_isFieldTypeDate:(NSString*)aType;
-- (BOOL)_isFieldTypeString:(NSString*)aType;
-- (BOOL)_isFieldTypeGeometry:(NSString*)aType;
-- (BOOL)_isFieldTypeAllowBinary:(NSString*)aType;
@end
@@ -55,15 +50,18 @@
- (id)init
{
if ((self = [super init])) {
+
tableFields = [[NSMutableArray alloc] init];
oldRow = [[NSMutableDictionary alloc] init];
enumFields = [[NSMutableDictionary alloc] init];
- typeSuggestions = nil;
-
- currentlyEditingRow = -1;
+
defaultValues = nil;
selectedTable = nil;
+ typeSuggestions = nil;
+ currentlyEditingRow = -1;
+ fieldValidation = [[SPTableFieldValidation alloc] init];
+
prefs = [NSUserDefaults standardUserDefaults];
}
@@ -82,6 +80,8 @@
[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]]];
+ // 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:
@"TINYINT",
@"SMALLINT",
@@ -131,7 +131,8 @@
@"MULTIPOLYGON",
@"GEOMETRYCOLLECTION",
nil] retain];
- // Hint: _isFieldTypeDate and _isFieldTypeNumeric must be changed if typeSuggestions was changed!
+
+ [fieldValidation setFieldTypes:typeSuggestions];
// Add observers for document task activity
[[NSNotificationCenter defaultCenter] addObserver:self
@@ -148,21 +149,23 @@
// Init the view column submenu according to saved hidden status;
// menu items are identified by their tag number which represents the initial column index
- for(NSMenuItem *item in [viewColumnsMenu itemArray]) [item setState:NSOnState]; // Set all items to NSOnState
- for(NSTableColumn *col in [tableSourceView tableColumns]) {
- if([col isHidden]) {
- if([[col identifier] isEqualToString:@"Key"])
+ for (NSMenuItem *item in [viewColumnsMenu itemArray]) [item setState:NSOnState]; // Set all items to NSOnState
+
+ for (NSTableColumn *col in [tableSourceView tableColumns])
+ {
+ if ([col isHidden]) {
+ if ([[col identifier] isEqualToString:@"Key"])
[[viewColumnsMenu itemWithTag:7] setState:NSOffState];
- else if([[col identifier] isEqualToString:@"encoding"])
+ else if ([[col identifier] isEqualToString:@"encoding"])
[[viewColumnsMenu itemWithTag:10] setState:NSOffState];
- else if([[col identifier] isEqualToString:@"collation"])
+ else if ([[col identifier] isEqualToString:@"collation"])
[[viewColumnsMenu itemWithTag:11] setState:NSOffState];
- else if([[col identifier] isEqualToString:@"comment"])
+ else if ([[col identifier] isEqualToString:@"comment"])
[[viewColumnsMenu itemWithTag:12] setState:NSOffState];
}
}
+
[tableSourceView reloadData];
-
}
#pragma mark -
@@ -207,7 +210,9 @@
[NSString stringWithFormat:NSLocalizedString(@"An error occurred while retrieving information.\nMySQL said: %@", @"message of panel when retrieving information failed"),
[mySQLConnection getLastErrorMessage]]);
}
+
if (indexResult) [indexResult release];
+
return;
}
@@ -216,8 +221,10 @@
[indexResult release];
// Set the Key column
- for(NSDictionary* theIndex in theTableIndexes) {
- for(id field in theTableFields) {
+ for (NSDictionary* theIndex in theTableIndexes)
+ {
+ for (id field in theTableFields)
+ {
if([[field objectForKey:@"name"] isEqualToString:[theIndex objectForKey:@"Column_name"]]) {
if([[theIndex objectForKey:@"Key_name"] isEqualToString:@"PRIMARY"])
[field setObject:@"PRI" forKey:@"Key"];
@@ -308,7 +315,6 @@
// For timestamps check to see whether "on update CURRENT_TIMESTAMP" and set Extra accordingly
else if ([type isEqualToString:@"TIMESTAMP"] && [[theField objectForKey:@"onupdatetimestamp"] integerValue])
[theField setObject:@"on update CURRENT_TIMESTAMP" forKey:@"Extra"];
-
}
// Set up the table details for the new table, and request an data/interface update
@@ -706,6 +712,14 @@
}
#pragma mark -
+#pragma mark Other IB action methods
+
+- (IBAction)unhideIndexesView:(id)sender
+{
+ [tablesIndexesSplitView setPosition:[tablesIndexesSplitView frame].size.height-130 ofDividerAtIndex:0];
+}
+
+#pragma mark -
#pragma mark Index sheet methods
/**
@@ -729,39 +743,23 @@
#pragma mark Additional methods
/**
- * Sets the connection (received from SPDatabaseDocument) and makes things that have to be done only once
- */
-- (void)setConnection:(MCPConnection *)theConnection
-{
- mySQLConnection = theConnection;
-
- // Set the indexes controller connection
- [indexesController setConnection:mySQLConnection];
-
- // Set up tableView
- [tableSourceView registerForDraggedTypes:[NSArray arrayWithObjects:SPDefaultPasteboardDragType, nil]];
-}
-
-/**
* Try table's auto_increment to a specific value
*
* @param valueAsString The new auto_increment integer as NSString
*/
- (void)setAutoIncrementTo:(NSString*)valueAsString
{
-
NSString *selTable = nil;
// if selectedTable is nil try to get the name from SPTablesList
- if(selectedTable == nil || ![selectedTable length])
+ if (selectedTable == nil || ![selectedTable length])
selTable = [tablesListInstance tableName];
else
selTable = [NSString stringWithString:selectedTable];
- if(selTable == nil || ![selTable length])
- return;
+ if (selTable == nil || ![selTable length]) return;
- if(valueAsString == nil || ![valueAsString length]) {
+ if (valueAsString == nil || ![valueAsString length]) {
// reload data and bail
[tableDataInstance resetAllData];
[extendedTableInfoInstance loadTable:selTable];
@@ -792,7 +790,6 @@
}
[tableInfoInstance tableChanged:nil];
-
}
/**
@@ -943,7 +940,7 @@
if(!specialFieldTypes) {
- if([self _isFieldTypeString:theRowType]) {
+ if ([fieldValidation isFieldTypeString:theRowType]) {
// Add CHARSET
NSString *fieldEncoding = @"";
if([[theRow objectForKey:@"encoding"] integerValue] > 0) {
@@ -970,7 +967,7 @@
}
}
- else if ([self _isFieldTypeNumeric:theRowType] && (![theRowType isEqualToString:@"BIT"])) {
+ else if ([fieldValidation isFieldTypeNumeric:theRowType] && (![theRowType isEqualToString:@"BIT"])) {
if ([[theRow objectForKey:@"unsigned"] integerValue] == 1) {
[queryString appendString:@"\n UNSIGNED"];
@@ -1010,7 +1007,7 @@
[queryString appendFormat:@"\n DEFAULT %@", [theRow objectForKey:@"default"]];
}
// Suppress appending DEFAULT clause for any numerics, date, time fields if default is empty to avoid error messages
- else if (![[theRow objectForKey:@"default"] length] && ([self _isFieldTypeNumeric:theRowType] || [self _isFieldTypeDate:theRowType])) {
+ else if (![[theRow objectForKey:@"default"] length] && ([fieldValidation isFieldTypeNumeric:theRowType] || [fieldValidation isFieldTypeDate:theRowType])) {
;
}
// Otherwise, use the provided default
@@ -1161,40 +1158,12 @@
}
/**
- * Perform the action requested in the Add Row error sheet.
- */
-- (void)addRowErrorSheetDidEnd:(NSAlert *)alert returnCode:(NSInteger)returnCode contextInfo:(void *)contextInfo
-{
-
- // Order out current sheet to suppress overlapping of sheets
- [[alert window] orderOut:nil];
-
- alertSheetOpened = NO;
-
- // Remain in edit mode - reselect the row and resume editing
- if (returnCode == NSAlertDefaultReturn) {
-
- // Problem: reentering edit mode for first cell doesn't function
- [tableSourceView selectRowIndexes:[NSIndexSet indexSetWithIndex:currentlyEditingRow] byExtendingSelection:NO];
- [tableSourceView performSelector:@selector(keyDown:) withObject:[NSEvent keyEventWithType:NSKeyDown location:NSMakePoint(0,0) modifierFlags:0 timestamp:0 windowNumber:[[tableDocumentInstance parentWindow] windowNumber] context:[NSGraphicsContext currentContext] characters:nil charactersIgnoringModifiers:nil isARepeat:NO keyCode:0x24] afterDelay:0.0];
- }
-
- // Discard changes and cancel editing
- else {
- [self cancelRowEditing];
- }
-
- [tableSourceView reloadData];
-}
-
-/**
* A method to show an error sheet after a short delay, so that it can
* be called from within an endSheet selector. This should be called on
* the main thread.
*/
--(void)showErrorSheetWith:(NSDictionary *)errorDictionary
+- (void)showErrorSheetWith:(NSDictionary *)errorDictionary
{
-
// If this method has been called directly, invoke a delay. Invoking the delay
// on the main thread ensures the timer fires on the main thread.
if (![errorDictionary objectForKey:@"delayed"]) {
@@ -1211,28 +1180,6 @@
}
/**
- * This method is called as part of Key Value Observing which is used to watch for preference changes which effect the interface.
- */
-- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
-{
- // Display table veiew vertical gridlines preference changed
- if ([keyPath isEqualToString:SPDisplayTableViewVerticalGridlines]) {
- [tableSourceView setGridStyleMask:([[change objectForKey:NSKeyValueChangeNewKey] boolValue]) ? NSTableViewSolidVerticalGridLineMask : NSTableViewGridNone];
- }
- // Use monospaced fonts preference changed
- else if ([keyPath isEqualToString:SPUseMonospacedFonts]) {
-
- BOOL useMonospacedFont = [[change objectForKey:NSKeyValueChangeNewKey] boolValue];
-
- [tableSourceView setFont:(useMonospacedFont) ? [NSFont fontWithName:SPDefaultMonospacedFontName size:[NSFont smallSystemFontSize]] : [NSFont systemFontOfSize:[NSFont smallSystemFontSize]]];
- [indexesTableView setFont:(useMonospacedFont) ? [NSFont fontWithName:SPDefaultMonospacedFontName size:[NSFont smallSystemFontSize]] : [NSFont systemFontOfSize:[NSFont smallSystemFontSize]]];
-
- [tableSourceView reloadData];
- [indexesTableView reloadData];
- }
-}
-
-/**
* Menu validation.
*/
- (BOOL)validateMenuItem:(NSMenuItem *)menuItem
@@ -1273,12 +1220,77 @@
alertSheetOpened = NO;
}
+/**
+ * Perform the action requested in the Add Row error sheet.
+ */
+- (void)addRowErrorSheetDidEnd:(NSAlert *)alert returnCode:(NSInteger)returnCode contextInfo:(void *)contextInfo
+{
+ // Order out current sheet to suppress overlapping of sheets
+ [[alert window] orderOut:nil];
+
+ alertSheetOpened = NO;
+
+ // Remain in edit mode - reselect the row and resume editing
+ if (returnCode == NSAlertDefaultReturn) {
+
+ // Problem: reentering edit mode for first cell doesn't function
+ [tableSourceView selectRowIndexes:[NSIndexSet indexSetWithIndex:currentlyEditingRow] byExtendingSelection:NO];
+ [tableSourceView performSelector:@selector(keyDown:) withObject:[NSEvent keyEventWithType:NSKeyDown location:NSMakePoint(0,0) modifierFlags:0 timestamp:0 windowNumber:[[tableDocumentInstance parentWindow] windowNumber] context:[NSGraphicsContext currentContext] characters:nil charactersIgnoringModifiers:nil isARepeat:NO keyCode:0x24] afterDelay:0.0];
+ }
+
+ // Discard changes and cancel editing
+ else {
+ [self cancelRowEditing];
+ }
+
+ [tableSourceView reloadData];
+}
+
+#pragma mark -
+#pragma mark KVO methods
+
+/**
+ * This method is called as part of Key Value Observing which is used to watch for preference changes which effect the interface.
+ */
+- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context
+{
+ // Display table veiew vertical gridlines preference changed
+ if ([keyPath isEqualToString:SPDisplayTableViewVerticalGridlines]) {
+ [tableSourceView setGridStyleMask:([[change objectForKey:NSKeyValueChangeNewKey] boolValue]) ? NSTableViewSolidVerticalGridLineMask : NSTableViewGridNone];
+ }
+ // Use monospaced fonts preference changed
+ else if ([keyPath isEqualToString:SPUseMonospacedFonts]) {
+
+ BOOL useMonospacedFont = [[change objectForKey:NSKeyValueChangeNewKey] boolValue];
+
+ [tableSourceView setFont:(useMonospacedFont) ? [NSFont fontWithName:SPDefaultMonospacedFontName size:[NSFont smallSystemFontSize]] : [NSFont systemFontOfSize:[NSFont smallSystemFontSize]]];
+ [indexesTableView setFont:(useMonospacedFont) ? [NSFont fontWithName:SPDefaultMonospacedFontName size:[NSFont smallSystemFontSize]] : [NSFont systemFontOfSize:[NSFont smallSystemFontSize]]];
+
+ [tableSourceView reloadData];
+ [indexesTableView reloadData];
+ }
+}
+
#pragma mark -
-#pragma mark Getter methods
+#pragma mark Accessors
/**
-get the default value for a specified field
-*/
+ * Sets the connection (received from SPDatabaseDocument) and makes things that have to be done only once
+ */
+- (void)setConnection:(MCPConnection *)theConnection
+{
+ mySQLConnection = theConnection;
+
+ // Set the indexes controller connection
+ [indexesController setConnection:mySQLConnection];
+
+ // Set up tableView
+ [tableSourceView registerForDraggedTypes:[NSArray arrayWithObjects:SPDefaultPasteboardDragType, nil]];
+}
+
+/**
+ * Get the default value for a specified field
+ */
- (NSString *)defaultValueForField:(NSString *)field
{
if ( ![defaultValues objectForKey:field] ) {
@@ -1291,8 +1303,8 @@ get the default value for a specified field
}
/**
-returns an array containing the field names of the selected table
-*/
+ * Returns an array containing the field names of the selected table
+ */
- (NSArray *)fieldNames
{
NSMutableArray *tempArray = [NSMutableArray array];
@@ -1314,8 +1326,8 @@ returns an array containing the field names of the selected table
}
/**
-returns a dictionary containing enum/set field names as key and possible values as array
-*/
+ * Returns a dictionary containing enum/set field names as key and possible values as array
+ */
- (NSDictionary *)enumFields
{
return [NSDictionary dictionaryWithDictionary:enumFields];
@@ -1449,75 +1461,8 @@ returns a dictionary containing enum/set field names as key and possible values
[refreshIndexesButton setEnabled:YES];
}
-- (IBAction)unhideIndexesView:(id)sender
-{
- [tablesIndexesSplitView setPosition:[tablesIndexesSplitView frame].size.height-130 ofDividerAtIndex:0];
-}
-
#pragma mark -
-#pragma mark Private API methods
-
-/**
- * Return if aType is numeric according to typeSuggestions's position
- * Hint: This must be changed if typeSuggestions was changed!
- */
-- (BOOL)_isFieldTypeNumeric:(NSString*)aType
-{
- NSString *type = [[aType stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]] uppercaseString];
-
- if(![typeSuggestions containsObject:type]) return YES; // for safety reasons
-
- return ([typeSuggestions indexOfObject:type] < 17);
-}
-
-/**
- * Return if aType is a date or time according to typeSuggestions's position
- * Hint: This must be changed if typeSuggestions was changed!
- */
-- (BOOL)_isFieldTypeDate:(NSString*)aType
-{
- NSString *type = [[aType stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]] uppercaseString];
-
- if(![typeSuggestions containsObject:type]) return YES; // for safety reasons
-
- return ([typeSuggestions indexOfObject:type] > 32 && [typeSuggestions indexOfObject:type] < 38);
-}
-
-/**
- * Return if aType is a geometry to typeSuggestions's position
- * Hint: This must be changed if typeSuggestions was changed!
- */
-- (BOOL)_isFieldTypeGeometry:(NSString*)aType
-{
- NSString *type = [[aType stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]] uppercaseString];
-
- if(![typeSuggestions containsObject:type]) return YES; // for safety reasons
-
- return ([typeSuggestions indexOfObject:type] > 38);
-}
-
-/**
- * Return if aType is a string type
- */
-- (BOOL)_isFieldTypeString:(NSString*)aType
-{
- NSString *type = [[aType stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]] uppercaseString];
-
- if(![typeSuggestions containsObject:type]) return YES; // for safety reasons
-
- return ([typeSuggestions indexOfObject:type] > 17 && [typeSuggestions indexOfObject:type] < 32);
-}
-/**
- * Return if aType is a string type
- */
-- (BOOL)_isFieldTypeAllowBinary:(NSString*)aType
-{
- NSString *type = [[aType stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]] uppercaseString];
-
- if(![typeSuggestions containsObject:type]) return YES; // for safety reasons
-
- return ([typeSuggestions indexOfObject:type] > 17 && [typeSuggestions indexOfObject:type] < 24);
-}
+#pragma mark Private API
/**
* Removes a field from the current table and the dependent foreign key if specified.
@@ -1598,6 +1543,8 @@ returns a dictionary containing enum/set field names as key and possible values
[oldRow release];
[enumFields release];
[typeSuggestions release];
+
+ [fieldValidation release], fieldValidation = nil;
if (defaultValues) [defaultValues release];
if (selectedTable) [selectedTable release];
diff --git a/Source/SPTableStructureDelegate.m b/Source/SPTableStructureDelegate.m
index d3954df7..b3246ca2 100644
--- a/Source/SPTableStructureDelegate.m
+++ b/Source/SPTableStructureDelegate.m
@@ -123,7 +123,7 @@
if(anObject && [(NSString*)anObject length] && ![(NSString*)anObject hasPrefix:@"--"]) {
[currentRow setObject:[(NSString*)anObject uppercaseString] forKey:@"type"];
// If type is BLOB or TEXT reset DEFAULT since these field types don't allow a default
- if([[currentRow objectForKey:@"type"] hasSuffix:@"TEXT"] || [[currentRow objectForKey:@"type"] hasSuffix:@"BLOB"] || [self _isFieldTypeGeometry:[currentRow objectForKey:@"type"]]) {
+ if([[currentRow objectForKey:@"type"] hasSuffix:@"TEXT"] || [[currentRow objectForKey:@"type"] hasSuffix:@"BLOB"] || [fieldValidation isFieldTypeGeometry:[currentRow objectForKey:@"type"]]) {
[currentRow setObject:@"" forKey:@"default"];
[currentRow setObject:@"" forKey:@"length"];
}
@@ -465,23 +465,23 @@
// Only string fields allow encoding settings
if(([[aTableColumn identifier] isEqualToString:@"encoding"])) {
- [aCell setEnabled:([self _isFieldTypeString:theRowType] && ![theRowType hasSuffix:@"BINARY"] && ![theRowType hasSuffix:@"BLOB"])];
+ [aCell setEnabled:([fieldValidation isFieldTypeString:theRowType] && ![theRowType hasSuffix:@"BINARY"] && ![theRowType hasSuffix:@"BLOB"])];
}
// Only string fields allow collation settings and string field is not set to BINARY since BINARY sets the collation to *_bin
else if([[aTableColumn identifier] isEqualToString:@"collation"]){
- [aCell setEnabled:([self _isFieldTypeString:theRowType] && [[theRow objectForKey:@"binary"] integerValue] == 0 && ![theRowType hasSuffix:@"BINARY"] && ![theRowType hasSuffix:@"BLOB"])];
+ [aCell setEnabled:([fieldValidation isFieldTypeString:theRowType] && [[theRow objectForKey:@"binary"] integerValue] == 0 && ![theRowType hasSuffix:@"BINARY"] && ![theRowType hasSuffix:@"BLOB"])];
}
// Check if UNSIGNED and ZEROFILL is allowed
else if([[aTableColumn identifier] isEqualToString:@"zerofill"] || [[aTableColumn identifier] isEqualToString:@"unsigned"]) {
- [aCell setEnabled:([self _isFieldTypeNumeric:theRowType])];
+ [aCell setEnabled:([fieldValidation isFieldTypeNumeric:theRowType])];
}
// Check if BINARY is allowed
else if([[aTableColumn identifier] isEqualToString:@"binary"]) {
- [aCell setEnabled:([self _isFieldTypeAllowBinary:theRowType])];
+ [aCell setEnabled:([fieldValidation isFieldTypeAllowBinary:theRowType])];
}
// TEXT, BLOB, and GEOMETRY fields don't allow a DEFAULT
else if([[aTableColumn identifier] isEqualToString:@"default"]) {
- [aCell setEnabled:([theRowType hasSuffix:@"TEXT"] || [theRowType hasSuffix:@"BLOB"] || [self _isFieldTypeGeometry:theRowType]) ? NO : YES];
+ [aCell setEnabled:([theRowType hasSuffix:@"TEXT"] || [theRowType hasSuffix:@"BLOB"] || [fieldValidation isFieldTypeGeometry:theRowType]) ? NO : YES];
}
// Check allow NULL
else if([[aTableColumn identifier] isEqualToString:@"null"]) {
@@ -489,7 +489,7 @@
}
// TEXT, BLOB, date, and GEOMETRY fields don't allow a length
else if([[aTableColumn identifier] isEqualToString:@"length"]) {
- [aCell setEnabled:([theRowType hasSuffix:@"TEXT"] || [theRowType hasSuffix:@"BLOB"] || [self _isFieldTypeDate:theRowType] || [self _isFieldTypeGeometry:theRowType]) ? NO : YES];
+ [aCell setEnabled:([theRowType hasSuffix:@"TEXT"] || [theRowType hasSuffix:@"BLOB"] || [fieldValidation isFieldTypeDate:theRowType] || [fieldValidation isFieldTypeGeometry:theRowType]) ? NO : YES];
}
else {
[aCell setEnabled:YES];
diff --git a/sequel-pro.xcodeproj/project.pbxproj b/sequel-pro.xcodeproj/project.pbxproj
index 1039488b..c9b87bf0 100644
--- a/sequel-pro.xcodeproj/project.pbxproj
+++ b/sequel-pro.xcodeproj/project.pbxproj
@@ -110,6 +110,7 @@
17CC97F710B4AC6C0034CD7A /* AboutPanel.xib in Resources */ = {isa = PBXBuildFile; fileRef = 17CC97F510B4AC6C0034CD7A /* AboutPanel.xib */; };
17CC993B10B4C9C80034CD7A /* License.rtf in Resources */ = {isa = PBXBuildFile; fileRef = 17CC993A10B4C9C80034CD7A /* License.rtf */; };
17D38EBC12771A1C00672B13 /* SPTableStructureDelegate.m in Sources */ = {isa = PBXBuildFile; fileRef = 17D38EBB12771A1C00672B13 /* SPTableStructureDelegate.m */; };
+ 17D38F701279E23A00672B13 /* SPTableFieldValidation.m in Sources */ = {isa = PBXBuildFile; fileRef = 17D38F6F1279E23A00672B13 /* SPTableFieldValidation.m */; };
17DC8E75126F4AB600E9AAEC /* MCPConnectionDelegate.h in Headers */ = {isa = PBXBuildFile; fileRef = 17DC8E74126F4AB600E9AAEC /* MCPConnectionDelegate.h */; settings = {ATTRIBUTES = (Public, ); }; };
17DCC5C7115C202700F89A00 /* MCPStringAdditions.h in Headers */ = {isa = PBXBuildFile; fileRef = 17DCC5C5115C202700F89A00 /* MCPStringAdditions.h */; };
17DD52B7115071D0007D8950 /* SPPrintTemplate.html in Resources */ = {isa = PBXBuildFile; fileRef = 17DD52B6115071D0007D8950 /* SPPrintTemplate.html */; };
@@ -665,6 +666,8 @@
17CC993A10B4C9C80034CD7A /* License.rtf */ = {isa = PBXFileReference; lastKnownFileType = text.rtf; path = License.rtf; sourceTree = "<group>"; };
17D38EBA12771A1C00672B13 /* SPTableStructureDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SPTableStructureDelegate.h; sourceTree = "<group>"; };
17D38EBB12771A1C00672B13 /* SPTableStructureDelegate.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SPTableStructureDelegate.m; sourceTree = "<group>"; };
+ 17D38F6E1279E23A00672B13 /* SPTableFieldValidation.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = SPTableFieldValidation.h; sourceTree = "<group>"; };
+ 17D38F6F1279E23A00672B13 /* SPTableFieldValidation.m */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.objc; path = SPTableFieldValidation.m; sourceTree = "<group>"; };
17DA04EA0FC1A7DA00D66140 /* Unit Tests-Info.plist */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = text.plist.xml; name = "Unit Tests-Info.plist"; path = "Plists/Unit Tests-Info.plist"; sourceTree = "<group>"; };
17DC8E74126F4AB600E9AAEC /* MCPConnectionDelegate.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MCPConnectionDelegate.h; sourceTree = "<group>"; };
17DCC5C5115C202700F89A00 /* MCPStringAdditions.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = MCPStringAdditions.h; sourceTree = "<group>"; };
@@ -1356,10 +1359,7 @@
17E6414F0EF01EF6001BC333 /* SPTableContent.m */,
17E641500EF01EF6001BC333 /* SPDatabaseDocument.h */,
17E641510EF01EF6001BC333 /* SPDatabaseDocument.m */,
- 17E641540EF01EF6001BC333 /* SPTableStructure.h */,
- 17E641550EF01EF6001BC333 /* SPTableStructure.m */,
- 17D38EBA12771A1C00672B13 /* SPTableStructureDelegate.h */,
- 17D38EBB12771A1C00672B13 /* SPTableStructureDelegate.m */,
+ 17D38F691279E17D00672B13 /* Table Structure */,
1792C28910AE1C7200ABE758 /* Controller Categories */,
);
name = "Main View Controllers";
@@ -1607,6 +1607,19 @@
name = "Data Import";
sourceTree = "<group>";
};
+ 17D38F691279E17D00672B13 /* Table Structure */ = {
+ isa = PBXGroup;
+ children = (
+ 17E641540EF01EF6001BC333 /* SPTableStructure.h */,
+ 17E641550EF01EF6001BC333 /* SPTableStructure.m */,
+ 17D38EBA12771A1C00672B13 /* SPTableStructureDelegate.h */,
+ 17D38EBB12771A1C00672B13 /* SPTableStructureDelegate.m */,
+ 17D38F6E1279E23A00672B13 /* SPTableFieldValidation.h */,
+ 17D38F6F1279E23A00672B13 /* SPTableFieldValidation.m */,
+ );
+ name = "Table Structure";
+ sourceTree = "<group>";
+ };
17DC8825126B222D00E9AAEC /* Third Party */ = {
isa = PBXGroup;
children = (
@@ -2932,6 +2945,7 @@
1798AB911267924D000D946A /* SPAppleScriptSupport.m in Sources */,
175EC63512733B36009A7C0F /* SPExportControllerDelegate.m in Sources */,
17D38EBC12771A1C00672B13 /* SPTableStructureDelegate.m in Sources */,
+ 17D38F701279E23A00672B13 /* SPTableFieldValidation.m in Sources */,
);
runOnlyForDeploymentPostprocessing = 0;
};
1638 1639 1640 1641 1642 1643 1644 1645 1646 1647 1648 1649 1650 1651 1652 1653 1654 1655 1656 1657 1658 1659 1660 1661 1662 1663 1664 1665 1666 1667 1668 1669 1670 1671 1672 1673 1674 1675 1676 1677 1678 1679 1680 1681 1682 1683 1684 1685 1686 1687 1688 1689 1690 1691 1692 1693 1694 1695 1696 1697 1698 1699 1700 1701 1702 1703 1704 1705 1706 1707 1708 1709 1710 1711 1712 1713 1714 1715 1716 1717 1718 1719 1720 1721 1722 1723 1724 1725 1726 1727 1728 1729 1730 1731 1732 1733 1734 1735 1736 1737 1738 1739 1740 1741 1742 1743 1744 1745 1746 1747 1748 1749 1750 1751 1752 1753 1754 1755 1756 1757 1758 1759 1760 1761 1762 1763 1764 1765 1766 1767 1768 1769 1770 1771 1772 1773 1774 1775 1776 1777 1778 1779 1780 1781 1782 1783 1784 1785 1786 1787 1788 1789 1790 1791 1792 1793 1794 1795 1796 1797 1798 1799 1800 1801 1802 1803 1804 1805 1806 1807 1808 1809 1810 1811 1812 1813 1814 1815 1816 1817 1818 1819 1820 1821 1822 1823 1824 1825 1826 1827 1828 1829 1830 1831 1832 1833 1834 1835 1836 1837 1838 1839 1840 1841 1842 1843 1844 1845 1846 1847 1848 1849 1850 1851 1852 1853 1854 1855 1856 1857 1858 1859 1860 1861 1862 1863 1864 1865 1866 1867 1868 1869 1870 1871 1872 1873 1874 1875 1876 1877 1878 1879 1880 1881 1882 1883 1884 1885 1886 1887 1888 1889 1890 1891 1892 1893 1894 1895 1896 1897 1898 1899 1900 1901 1902 1903 1904 1905 1906 1907 1908 1909 1910 1911 1912 1913 1914 1915 1916 1917 1918 1919 1920 1921 1922 1923 1924 1925 1926 1927 1928 1929 1930 1931 1932 1933 1934 1935 1936 1937 1938 1939 1940 1941 1942 1943 1944 1945 1946 1947 1948 1949 1950 1951 1952 1953 1954 1955 1956 1957 1958 1959 1960 1961 1962 1963 1964 1965 1966 1967 1968 1969 1970 1971 1972 1973 1974 1975 1976 1977 1978 1979 1980 1981 1982 1983 1984 1985 1986 1987 1988 1989 1990 1991 1992 1993 1994 1995 1996 1997 1998 1999 2000 2001 2002 2003 2004 2005 2006 2007 2008 2009 2010 2011 2012 2013 2014 2015 2016 2017 2018 2019 2020 2021 2022 2023 2024 2025 2026 2027 2028 2029 2030 2031 2032 2033 2034 2035 2036 2037 2038 2039 2040 2041 2042 2043 2044 2045 2046 2047 2048 2049 2050 2051 2052 2053 2054 2055 2056 2057 2058 2059 2060 2061 2062 2063 2064 2065 2066 2067 2068 2069 2070 2071 2072 2073 2074 2075 2076 2077 2078 2079 2080 2081 2082 2083 2084 2085 2086 2087 2088 2089 2090 2091 2092 2093 2094 2095 2096 2097 2098 2099 2100 2101 2102 2103 2104 2105 2106 2107 2108 2109 2110 2111 2112 2113 2114 2115 2116 2117 2118 2119 2120 2121 2122 2123 2124 2125 2126 2127 2128 2129 2130 2131 2132 2133 2134 2135 2136 2137 2138 2139 2140 2141 2142 2143 2144 2145 2146 2147 2148 2149 2150 2151 2152 2153 2154 2155 2156 2157 2158 2159 2160 2161 2162 2163 2164 2165 2166 2167 2168 2169 2170 2171 2172 2173 2174 2175 2176 2177 2178 2179 2180 2181 2182 2183 2184 2185 2186 2187 2188 2189 2190 2191 2192 2193 2194 2195 2196 2197 2198 2199 2200 2201 2202 2203 2204 2205 2206 2207 2208 2209 2210 2211 2212 2213 2214 2215 2216 2217 2218 2219 2220 2221 2222 2223 2224 2225 2226 2227 2228 2229 2230 2231 2232 2233 2234 2235 2236 2237 2238 2239 2240 2241 2242 2243 2244 2245 2246 2247 2248 2249 2250 2251 2252 2253 2254 2255 2256 2257 2258 2259 2260 2261 2262 2263 2264 2265 2266 2267 2268 2269 2270 2271 2272 2273 2274 2275 2276