aboutsummaryrefslogtreecommitdiffstats
path: root/Source
diff options
context:
space:
mode:
authorstuconnolly <stuart02@gmail.com>2012-07-16 09:06:58 +0000
committerstuconnolly <stuart02@gmail.com>2012-07-16 09:06:58 +0000
commit1d287a60914e27503c9b6c7218600ca83cc8040b (patch)
tree4017776a56f5c1066c204b00929db88b1437a12b /Source
parent4cd26629de78580fad186f0beeaa3c2ebcd1a374 (diff)
downloadsequelpro-1d287a60914e27503c9b6c7218600ca83cc8040b.tar.gz
sequelpro-1d287a60914e27503c9b6c7218600ca83cc8040b.tar.bz2
sequelpro-1d287a60914e27503c9b6c7218600ca83cc8040b.zip
Fix the display of the encoding and collation of fields that don't support them (introduced in r3708). This also fixes the issue of re-ordering non-string fields failing due to the encoding and collaction being included.
Diffstat (limited to 'Source')
-rw-r--r--Source/SPTableFieldValidation.h2
-rw-r--r--Source/SPTableStructureDelegate.m48
-rw-r--r--Source/SPTableStructureLoading.m18
3 files changed, 35 insertions, 33 deletions
diff --git a/Source/SPTableFieldValidation.h b/Source/SPTableFieldValidation.h
index b9d973dd..bf9c587a 100644
--- a/Source/SPTableFieldValidation.h
+++ b/Source/SPTableFieldValidation.h
@@ -29,7 +29,7 @@
}
/**
- * @property fieldTypes Field types array
+ * @property fieldTypes Field types array.
*/
@property (readwrite, retain) NSArray *fieldTypes;
diff --git a/Source/SPTableStructureDelegate.m b/Source/SPTableStructureDelegate.m
index 084fb4d0..4a4dc930 100644
--- a/Source/SPTableStructureDelegate.m
+++ b/Source/SPTableStructureDelegate.m
@@ -210,11 +210,12 @@
if (aTableView != tableSourceView) return NO;
// Check whether a save of the current field row is required.
- if ( ![self saveRowOnDeselect] ) return NO;
+ if (![self saveRowOnDeselect]) return NO;
if ([rows count] == 1) {
[pboard declareTypes:[NSArray arrayWithObject:SPDefaultPasteboardDragType] owner:nil];
[pboard setString:[[NSNumber numberWithInteger:[rows firstIndex]] stringValue] forType:SPDefaultPasteboardDragType];
+
return YES;
}
else {
@@ -258,21 +259,18 @@
{
// Make sure that the drag operation is for the right table view
if (tableView != tableSourceView) return NO;
-
- NSInteger originalRowIndex;
- NSMutableString *queryString;
- NSDictionary *originalRow;
-
+
// Extract the original row position from the pasteboard and retrieve the details
- originalRowIndex = [[[info draggingPasteboard] stringForType:SPDefaultPasteboardDragType] integerValue];
- originalRow = [[NSDictionary alloc] initWithDictionary:[tableFields objectAtIndex:originalRowIndex]];
+ NSInteger originalRowIndex = [[[info draggingPasteboard] stringForType:SPDefaultPasteboardDragType] integerValue];
+ NSDictionary *originalRow = [[NSDictionary alloc] initWithDictionary:[tableFields objectAtIndex:originalRowIndex]];
[[NSNotificationCenter defaultCenter] postNotificationName:@"SMySQLQueryWillBePerformed" object:tableDocumentInstance];
+ NSString *fieldType = [[originalRow objectForKey:@"type"] uppercaseString];
+
// Begin construction of the reordering query
- queryString = [NSMutableString stringWithFormat:@"ALTER TABLE %@ MODIFY COLUMN %@ %@", [selectedTable backtickQuotedString],
- [[originalRow objectForKey:@"name"] backtickQuotedString],
- [[originalRow objectForKey:@"type"] uppercaseString]];
+ NSMutableString *queryString = [NSMutableString stringWithFormat:@"ALTER TABLE %@ MODIFY COLUMN %@ %@", [selectedTable backtickQuotedString],
+ [[originalRow objectForKey:@"name"] backtickQuotedString], fieldType];
// Add the length parameter if necessary
if ([originalRow objectForKey:@"length"] && ![[originalRow objectForKey:@"length"] isEqualToString:@""]) {
@@ -280,12 +278,14 @@
}
NSString *fieldEncoding = @"";
-
+
if ([[originalRow objectForKey:@"encoding"] integerValue] > 0) {
NSString *enc = [[encodingPopupCell itemAtIndex:[[originalRow objectForKey:@"encoding"] integerValue]] title];
- NSInteger start = [enc rangeOfString:@"("].location+1;
- NSInteger end = [enc length] - start - 1;
- fieldEncoding = [enc substringWithRange:NSMakeRange(start, end)];
+
+ NSInteger start = [enc rangeOfString:@"("].location + 1;
+
+ fieldEncoding = [enc substringWithRange:NSMakeRange(start, [enc length] - start - 1)];
+
[queryString appendFormat:@" CHARACTER SET %@", fieldEncoding];
}
@@ -295,7 +295,8 @@
if ([fieldEncoding length] && [[originalRow objectForKey:@"collation"] integerValue] > 0) {
NSArray *theCollations = [databaseDataInstance getDatabaseCollationsForEncoding:fieldEncoding];
- NSString *col = [[theCollations objectAtIndex:[[originalRow objectForKey:@"collation"] integerValue]-1] objectForKey:@"COLLATION_NAME"];
+ NSString *col = [[theCollations objectAtIndex:[[originalRow objectForKey:@"collation"] integerValue] - 1] objectForKey:@"COLLATION_NAME"];
+
[queryString appendFormat:@" COLLATE %@", col];
}
@@ -321,7 +322,7 @@
[queryString appendString:[[originalRow objectForKey:@"Extra"] uppercaseString]];
}
- BOOL isTimestampType = [[[originalRow objectForKey:@"type"] lowercaseString] isEqualToString:@"timestamp"];
+ BOOL isTimestampType = [fieldType isEqualToString:@"TIMESTAMP"];
// Add the default value, skip it for auto_increment
if ([originalRow objectForKey:@"Extra"] && ![[originalRow objectForKey:@"Extra"] isEqualToString:@"auto_increment"]) {
@@ -349,11 +350,12 @@
}
// Add the new location
- if ( destinationRowIndex == 0 ){
+ if (destinationRowIndex == 0) {
[queryString appendString:@" FIRST"];
- } else {
+ }
+ else {
[queryString appendFormat:@" AFTER %@",
- [[[tableFields objectAtIndex:destinationRowIndex-1] objectForKey:@"name"] backtickQuotedString]];
+ [[[tableFields objectAtIndex:destinationRowIndex - 1] objectForKey:@"name"] backtickQuotedString]];
}
// Run the query; report any errors, or reload the table on success
@@ -371,11 +373,7 @@
// Mark the content table cache for refresh
[tableDocumentInstance setContentRequiresReload:YES];
- if ( originalRowIndex < destinationRowIndex ) {
- [tableSourceView selectRowIndexes:[NSIndexSet indexSetWithIndex:destinationRowIndex-1] byExtendingSelection:NO];
- } else {
- [tableSourceView selectRowIndexes:[NSIndexSet indexSetWithIndex:destinationRowIndex] byExtendingSelection:NO];
- }
+ [tableSourceView selectRowIndexes:[NSIndexSet indexSetWithIndex:destinationRowIndex - (originalRowIndex < destinationRowIndex) ? 1 : 0] byExtendingSelection:NO];
}
[[NSNotificationCenter defaultCenter] postNotificationName:@"SMySQLQueryHasBeenPerformed" object:tableDocumentInstance];
diff --git a/Source/SPTableStructureLoading.m b/Source/SPTableStructureLoading.m
index 40b731a5..a30d7c63 100644
--- a/Source/SPTableStructureLoading.m
+++ b/Source/SPTableStructureLoading.m
@@ -148,8 +148,8 @@
NSString *collation = nil;
NSString *encoding = nil;
- if ([fieldValidation isFieldTypeString:type] || ![type hasSuffix:@"BINARY"] || ![type hasSuffix:@"BLOB"]) {
-
+ if ([fieldValidation isFieldTypeString:type] && ![type hasSuffix:@"BINARY"] && ![type hasSuffix:@"BLOB"]) {
+
collation = [theField objectForKey:@"collation"] ? [theField objectForKey:@"collation"] : [[tableDataInstance statusValues] objectForKey:@"collation"];
encoding = [theField objectForKey:@"encoding"] ? [theField objectForKey:@"encoding"] : [tableDataInstance tableEncoding];
@@ -214,21 +214,25 @@
[theField setObject:[NSString stringWithFormat:@"%@,%@", [theField objectForKey:@"length"], [theField objectForKey:@"decimals"]] forKey:@"length"];
// Normalize default
- if(![theField objectForKey:@"default"])
+ if (![theField objectForKey:@"default"]) {
[theField setObject:@"" forKey:@"default"];
- else if([[theField objectForKey:@"default"] isNSNull])
+ }
+ else if ([[theField objectForKey:@"default"] isNSNull]) {
[theField setObject:[prefs stringForKey:SPNullValue] forKey:@"default"];
+ }
// Init Extra field
[theField setObject:@"None" forKey:@"Extra"];
// Check for auto_increment and set Extra accordingly
- if([[theField objectForKey:@"autoincrement"] integerValue])
+ if ([[theField objectForKey:@"autoincrement"] integerValue]) {
[theField setObject:@"auto_increment" forKey:@"Extra"];
+ }
// For timestamps check to see whether "on update CURRENT_TIMESTAMP" and set Extra accordingly
- else if ([type isEqualToString:@"TIMESTAMP"] && [[theField objectForKey:@"onupdatetimestamp"] integerValue])
+ 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
@@ -274,7 +278,7 @@
*
* Should be called on the main thread.
*/
-- (void) setTableDetails:(NSDictionary *)tableDetails
+- (void)setTableDetails:(NSDictionary *)tableDetails
{
NSString *newTableName = [tableDetails objectForKey:@"name"];
NSMutableDictionary *newDefaultValues;