diff options
author | stuconnolly <stuart02@gmail.com> | 2010-07-02 22:53:37 +0000 |
---|---|---|
committer | stuconnolly <stuart02@gmail.com> | 2010-07-02 22:53:37 +0000 |
commit | f57748788a3d9054e5e6c88e8a187e15e5bd7b2d (patch) | |
tree | c125ffb8bbc2f492677d1a77c4c311b236f5e58f /Source | |
parent | 8af000934e13e1ed0f9bb73c26bfdc8b156d6525 (diff) | |
download | sequelpro-f57748788a3d9054e5e6c88e8a187e15e5bd7b2d.tar.gz sequelpro-f57748788a3d9054e5e6c88e8a187e15e5bd7b2d.tar.bz2 sequelpro-f57748788a3d9054e5e6c88e8a187e15e5bd7b2d.zip |
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.
Diffstat (limited to 'Source')
-rw-r--r-- | Source/SPTableStructure.m | 15 |
1 files 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]; |