From f57748788a3d9054e5e6c88e8a187e15e5bd7b2d Mon Sep 17 00:00:00 2001 From: stuconnolly Date: Fri, 2 Jul 2010 22:53:37 +0000 Subject: When reordering a timestamp field ensure the query is correctly constructed when it allows NULL values. Fixes issue #753. Also, improve the error message displayed when a field cannot be moved. --- Source/SPTableStructure.m | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/Source/SPTableStructure.m b/Source/SPTableStructure.m index 01b9cd5d..957ea21c 100644 --- a/Source/SPTableStructure.m +++ b/Source/SPTableStructure.m @@ -1364,15 +1364,19 @@ would result in a position change. [queryString appendString:@" "]; [queryString appendString:[[originalRow objectForKey:@"Extra"] uppercaseString]]; } + + BOOL isTimestampType = [[originalRow objectForKey:@"Type"] isEqualToString:@"timestamp"]; // Add the default value if ([[originalRow objectForKey:@"Default"] isEqualToString:[prefs objectForKey:SPNullValue]]) { if ([[originalRow objectForKey:@"Null"] integerValue] == 1) { - [queryString appendString:@" DEFAULT NULL"]; + [queryString appendString:(isTimestampType) ? @" NULL DEFAULT NULL" : @" DEFAULT NULL"]; } - } else if ( [[originalRow objectForKey:@"Type"] isEqualToString:@"timestamp"] && ([[[originalRow objectForKey:@"Default"] uppercaseString] isEqualToString:@"CURRENT_TIMESTAMP"]) ) { + } + else if (isTimestampType && ([[[originalRow objectForKey:@"Default"] uppercaseString] isEqualToString:@"CURRENT_TIMESTAMP"]) ) { [queryString appendString:@" DEFAULT CURRENT_TIMESTAMP"]; - } else { + } + else { [queryString appendString:[NSString stringWithFormat:@" DEFAULT '%@'", [mySQLConnection prepareString:[originalRow objectForKey:@"Default"]]]]; } @@ -1399,9 +1403,10 @@ would result in a position change. // Run the query; report any errors, or reload the table on success [mySQLConnection queryString:queryString]; + if ([mySQLConnection queryErrored]) { - SPBeginAlertSheet(NSLocalizedString(@"Error", @"error"), NSLocalizedString(@"OK", @"OK button"), nil, nil, [tableDocumentInstance parentWindow], self, nil, nil, - [NSString stringWithFormat:NSLocalizedString(@"Couldn't move field. MySQL said: %@", @"message of panel when field cannot be added in drag&drop operation"), [mySQLConnection getLastErrorMessage]]); + SPBeginAlertSheet(NSLocalizedString(@"Error moving field", @"error moving field message"), NSLocalizedString(@"OK", @"OK button"), nil, nil, [tableDocumentInstance parentWindow], self, nil, nil, + [NSString stringWithFormat:NSLocalizedString(@"An error occurred while trying to move the field.\n\nMySQL said: %@", @"error moving field informative message"), [mySQLConnection getLastErrorMessage]]); } else { [tableDataInstance resetAllData]; [tablesListInstance setStatusRequiresReload:YES]; -- cgit v1.2.3