aboutsummaryrefslogtreecommitdiffstats
path: root/Source/SPTableStructureDelegate.m
diff options
context:
space:
mode:
authorMax <post@wickenrode.com>2015-11-03 19:37:18 +0100
committerMax <post@wickenrode.com>2015-11-03 19:37:18 +0100
commitddaa4619f1ef9aedf4fbfd156df8b7b71c3e286b (patch)
tree8e9c383787deb160cf9ef19380cc9371b3ef4826 /Source/SPTableStructureDelegate.m
parent945f6c56aa6a8cb10be924cc3331789c10e53e57 (diff)
downloadsequelpro-ddaa4619f1ef9aedf4fbfd156df8b7b71c3e286b.tar.gz
sequelpro-ddaa4619f1ef9aedf4fbfd156df8b7b71c3e286b.tar.bz2
sequelpro-ddaa4619f1ef9aedf4fbfd156df8b7b71c3e286b.zip
Remove duplicate code for ALTER statement when reordering columns via drag&drop in table structure view
Diffstat (limited to 'Source/SPTableStructureDelegate.m')
-rw-r--r--Source/SPTableStructureDelegate.m84
1 files changed, 8 insertions, 76 deletions
diff --git a/Source/SPTableStructureDelegate.m b/Source/SPTableStructureDelegate.m
index 62485b26..3ff4d6e4 100644
--- a/Source/SPTableStructureDelegate.m
+++ b/Source/SPTableStructureDelegate.m
@@ -62,6 +62,7 @@ static void _BuildMenuWithPills(NSMenu *menu,struct _cmpMap *map,size_t mapEntri
@interface SPTableStructure (PrivateAPI)
- (void)sheetDidEnd:(id)sheet returnCode:(NSInteger)returnCode contextInfo:(NSString *)contextInfo;
+- (NSString *)_buildPartialColumnDefinitionString:(NSDictionary *)theRow;
@end
@@ -351,88 +352,19 @@ static void _BuildMenuWithPills(NSMenu *menu,struct _cmpMap *map,size_t mapEntri
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
- 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:@""]) {
- [queryString appendFormat:@"(%@)", [originalRow objectForKey:@"length"]];
- }
-
- NSString *fieldEncoding = [originalRow objectForKey:@"encodingName"];
- if ([fieldEncoding length] && [[tableDocumentInstance serverSupport] supportsPost41CharacterSetHandling]) {
- [queryString appendFormat:@" CHARACTER SET %@", fieldEncoding];
- }
-
- if (![fieldEncoding length] && [tableDataInstance tableEncoding]) {
- fieldEncoding = [tableDataInstance tableEncoding];
- }
-
- NSString *fieldCollation = [originalRow objectForKey:@"collationName"];
- if ([fieldEncoding length] && [fieldCollation length] && ![[originalRow objectForKey:@"binary"] integerValue]) {
- [queryString appendFormat:@" COLLATE %@", fieldCollation];
- }
+ // Begin construction of the reordering query
+ NSMutableString *queryString = [NSMutableString stringWithFormat:@"ALTER TABLE %@ MODIFY COLUMN %@",
+ [selectedTable backtickQuotedString],
+ [self _buildPartialColumnDefinitionString:originalRow]];
- // Add unsigned, zerofill, binary, not null if necessary
- if ([[originalRow objectForKey:@"unsigned"] integerValue]) {
- [queryString appendString:@" UNSIGNED"];
- }
-
- if ([[originalRow objectForKey:@"zerofill"] integerValue]) {
- [queryString appendString:@" ZEROFILL"];
- }
-
- if ([[originalRow objectForKey:@"binary"] integerValue]) {
- [queryString appendString:@" BINARY"];
- }
-
- if (![[originalRow objectForKey:@"null"] integerValue]) {
- [queryString appendString:@" NOT NULL"];
- }
-
- if (![[originalRow objectForKey:@"Extra"] isEqualToString:@"None"] ) {
- [queryString appendString:@" "];
- [queryString appendString:[[originalRow objectForKey:@"Extra"] uppercaseString]];
- }
-
- BOOL isTimestampType = [fieldType isEqualToString:@"TIMESTAMP"];
-
- // Add the default value, skip it for auto_increment
- if ([originalRow objectForKey:@"Extra"] && ![[originalRow objectForKey:@"Extra"] isEqualToString:@"auto_increment"]) {
- if ([[originalRow objectForKey:@"default"] isEqualToString:[prefs objectForKey:SPNullValue]]) {
- if ([[originalRow objectForKey:@"null"] integerValue] == 1) {
- [queryString appendString:(isTimestampType) ? @" NULL DEFAULT NULL" : @" DEFAULT NULL"];
- }
- }
- else if (isTimestampType && ([[[originalRow objectForKey:@"default"] uppercaseString] isEqualToString:@"CURRENT_TIMESTAMP"]) ) {
- [queryString appendString:@" DEFAULT CURRENT_TIMESTAMP"];
- }
- else if ([(NSString *)[originalRow objectForKey:@"default"] length]) {
- [queryString appendFormat:@" DEFAULT %@", [mySQLConnection escapeAndQuoteString:[originalRow objectForKey:@"default"]]];
- }
- }
-
- // Any column comments
- if ([(NSString *)[originalRow objectForKey:@"comment"] length]) {
- [queryString appendFormat:@" COMMENT %@", [mySQLConnection escapeAndQuoteString:[originalRow objectForKey:@"comment"]]];
- }
-
- // Unparsed details - column formats, storage, reference definitions
- if ([originalRow objectForKey:@"unparsed"]) {
- [queryString appendString:[originalRow objectForKey:@"unparsed"]];
- }
-
+ [queryString appendString:@" "];
// Add the new location
if (destinationRowIndex == 0) {
- [queryString appendString:@" FIRST"];
+ [queryString appendString:@"FIRST"];
}
else {
- [queryString appendFormat:@" AFTER %@", [[[tableFields objectAtIndex:destinationRowIndex - 1] objectForKey:@"name"] backtickQuotedString]];
+ [queryString appendFormat:@"AFTER %@", [[[tableFields objectAtIndex:destinationRowIndex - 1] objectForKey:@"name"] backtickQuotedString]];
}
// Run the query; report any errors, or reload the table on success