aboutsummaryrefslogtreecommitdiffstats
path: root/Source/SPTableStructure.m
diff options
context:
space:
mode:
authorMax <post@wickenrode.com>2015-06-09 00:33:17 +0200
committerMax <post@wickenrode.com>2015-06-09 21:56:08 +0200
commit4a11179260951f597cf52d86581d68cd8a98b68d (patch)
tree101c44172370c66f335686d8f6f1e517a9a51f1b /Source/SPTableStructure.m
parent622bb0298ccc9b4b6c407604e977b77275c2aa3e (diff)
downloadsequelpro-4a11179260951f597cf52d86581d68cd8a98b68d.tar.gz
sequelpro-4a11179260951f597cf52d86581d68cd8a98b68d.tar.bz2
sequelpro-4a11179260951f597cf52d86581d68cd8a98b68d.zip
Setting large auto_increment values (> 1000) could be misinterpreted as decimal values in some cases (fixes #2130)
Diffstat (limited to 'Source/SPTableStructure.m')
-rw-r--r--Source/SPTableStructure.m26
1 files changed, 16 insertions, 10 deletions
diff --git a/Source/SPTableStructure.m b/Source/SPTableStructure.m
index 992ecdcf..cdc1c8c7 100644
--- a/Source/SPTableStructure.m
+++ b/Source/SPTableStructure.m
@@ -490,7 +490,7 @@ static NSString *SPRemoveFieldAndForeignKey = @"SPRemoveFieldAndForeignKey";
[resetAutoIncrementValue setStringValue:@"1"];
}
else if ([sender tag] == 2) {
- [self setAutoIncrementTo:@"1"];
+ [self setAutoIncrementTo:@1];
}
#endif
}
@@ -505,11 +505,21 @@ static NSString *SPRemoveFieldAndForeignKey = @"SPRemoveFieldAndForeignKey";
[theSheet orderOut:nil];
if (returnCode == NSAlertDefaultReturn) {
- [self setAutoIncrementTo:[[resetAutoIncrementValue stringValue] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]];
+ [self takeAutoIncrementFrom:resetAutoIncrementValue];
}
#endif
}
+- (void)takeAutoIncrementFrom:(NSTextField *)field
+{
+ id obj = [field objectValue];
+ //nil is handled by -setAutoIncrementTo:
+ if(obj && ![obj isKindOfClass:[NSNumber class]]) {
+ [NSException raise:NSInternalInconsistencyException format:@"[$field objectValue] should return NSNumber *, but was %@",[obj class]];
+ }
+ [self setAutoIncrementTo:(NSNumber *)obj];
+}
+
/**
* Process the remove field sheet closing, performing the delete if the user
* confirmed the action.
@@ -600,13 +610,13 @@ static NSString *SPRemoveFieldAndForeignKey = @"SPRemoveFieldAndForeignKey";
*
* @param valueAsString The new auto_increment integer as NSString
*/
-- (void)setAutoIncrementTo:(NSString*)valueAsString
+- (void)setAutoIncrementTo:(NSNumber *)value
{
NSString *selTable = [tablesListInstance tableName];
if (selTable == nil || ![selTable length]) return;
- if (valueAsString == nil || ![valueAsString length]) {
+ if (value == nil) {
// reload data and bail
[tableDataInstance resetAllData];
#ifndef SP_CODA
@@ -616,12 +626,8 @@ static NSString *SPRemoveFieldAndForeignKey = @"SPRemoveFieldAndForeignKey";
return;
}
- NSNumberFormatter *formatter = [[NSNumberFormatter alloc] init];
- [formatter setNumberStyle:NSNumberFormatterDecimalStyle];
- NSNumber *autoIncValue = [formatter numberFromString:valueAsString];
- [formatter release];
-
- [mySQLConnection queryString:[NSString stringWithFormat:@"ALTER TABLE %@ AUTO_INCREMENT = %@", [selTable backtickQuotedString], [autoIncValue stringValue]]];
+ // only int and float types can be AUTO_INCREMENT and right now BIGINT = 64 Bit (<= long long) is the largest type mysql supports
+ [mySQLConnection queryString:[NSString stringWithFormat:@"ALTER TABLE %@ AUTO_INCREMENT = %llu", [selTable backtickQuotedString], [value unsignedLongLongValue]]];
if ([mySQLConnection queryErrored]) {
SPBeginAlertSheet(NSLocalizedString(@"Error", @"error"),