aboutsummaryrefslogtreecommitdiffstats
path: root/Source
diff options
context:
space:
mode:
authorMax <post@wickenrode.com>2015-06-09 00:33:17 +0200
committerMax <post@wickenrode.com>2015-06-09 00:33:17 +0200
commitfb54e89b78a8d72c433db83ed435564770d7b895 (patch)
treebc012fe91dd507b2c64678d05534ce5ddfab09e1 /Source
parentbe4532c4215b839fc73c167a778a00d33683e461 (diff)
downloadsequelpro-fb54e89b78a8d72c433db83ed435564770d7b895.tar.gz
sequelpro-fb54e89b78a8d72c433db83ed435564770d7b895.tar.bz2
sequelpro-fb54e89b78a8d72c433db83ed435564770d7b895.zip
Setting large auto_increment values (> 1000) could be misinterpreted as decimal values in some cases (fixes #2130)
Diffstat (limited to 'Source')
-rw-r--r--Source/SPExtendedTableInfo.h2
-rw-r--r--Source/SPExtendedTableInfo.m5
-rw-r--r--Source/SPTableContent.m2
-rw-r--r--Source/SPTableData.m1
-rw-r--r--Source/SPTableStructure.h3
-rw-r--r--Source/SPTableStructure.m26
6 files changed, 24 insertions, 15 deletions
diff --git a/Source/SPExtendedTableInfo.h b/Source/SPExtendedTableInfo.h
index 3af8b523..9dd249d9 100644
--- a/Source/SPExtendedTableInfo.h
+++ b/Source/SPExtendedTableInfo.h
@@ -75,7 +75,7 @@
- (IBAction)updateTableEncoding:(id)sender;
- (IBAction)updateTableCollation:(id)sender;
- (IBAction)resetAutoIncrement:(id)sender;
-- (IBAction)resetAutoIncrementValueWasEdited:(id)sender;
+- (IBAction)tableRowAutoIncrementWasEdited:(id)sender;
// Others
- (void)loadTable:(NSString *)table;
diff --git a/Source/SPExtendedTableInfo.m b/Source/SPExtendedTableInfo.m
index 3d27b821..d3b332d0 100644
--- a/Source/SPExtendedTableInfo.m
+++ b/Source/SPExtendedTableInfo.m
@@ -216,10 +216,11 @@ static NSString *SPMySQLCommentField = @"Comment";
}
}
-- (IBAction)resetAutoIncrementValueWasEdited:(id)sender
+- (IBAction)tableRowAutoIncrementWasEdited:(id)sender
{
[tableRowAutoIncrement setEditable:NO];
- [tableSourceInstance setAutoIncrementTo:[[tableRowAutoIncrement stringValue] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]];
+
+ [tableSourceInstance takeAutoIncrementFrom:tableRowAutoIncrement];
}
- (BOOL)control:(NSControl *)control textView:(NSTextView *)textView doCommandBySelector:(SEL)command
diff --git a/Source/SPTableContent.m b/Source/SPTableContent.m
index 308c101b..6988b0f3 100644
--- a/Source/SPTableContent.m
+++ b/Source/SPTableContent.m
@@ -2038,7 +2038,7 @@ static NSString *SPTableFilterSetDefaultOperator = @"SPTableFilterSetDefaultOper
// Reset auto increment if suppression button was ticked
if([[alert suppressionButton] state] == NSOnState) {
- [tableSourceInstance setAutoIncrementTo:@"1"];
+ [tableSourceInstance setAutoIncrementTo:@1];
#ifndef SP_CODA
[prefs setBool:YES forKey:SPResetAutoIncrementAfterDeletionOfAllRows];
#endif
diff --git a/Source/SPTableData.m b/Source/SPTableData.m
index bdd1f1db..d477b444 100644
--- a/Source/SPTableData.m
+++ b/Source/SPTableData.m
@@ -575,6 +575,7 @@
returningInclusively: NO
ignoringQuotedStrings: NO];
if(fieldName == nil || [fieldName length] == 0) {
+#warning NSAlert from background thread! (This whole function needs improvement)
NSBeep();
NSAlert *alert = [[NSAlert alloc] init];
[alert addButtonWithTitle:NSLocalizedString(@"OK", @"OK button")];
diff --git a/Source/SPTableStructure.h b/Source/SPTableStructure.h
index f3d99ea6..781717f8 100644
--- a/Source/SPTableStructure.h
+++ b/Source/SPTableStructure.h
@@ -129,6 +129,7 @@
- (void)removeFieldSheetDidEnd:(NSAlert *)alert returnCode:(NSInteger)returnCode contextInfo:(void *)contextInfo;
- (IBAction)resetAutoIncrement:(id)sender;
- (void)resetAutoincrementSheetDidEnd:(NSWindow *)theSheet returnCode:(NSInteger)returnCode contextInfo:(void *)contextInfo;
+- (void)takeAutoIncrementFrom:(NSTextField *)field;
- (IBAction)showOptimizedFieldType:(id)sender;
- (IBAction)toggleColumnView:(NSMenuItem *)sender;
- (BOOL)cancelRowEditing;
@@ -142,7 +143,7 @@
- (BOOL)saveRowOnDeselect;
- (BOOL)addRowToDB;
- (void)addRowErrorSheetDidEnd:(NSAlert *)alert returnCode:(NSInteger)returnCode contextInfo:(void *)contextInfo;
-- (void)setAutoIncrementTo:(NSString*)valueAsString;
+- (void)setAutoIncrementTo:(NSNumber *)value;
// Accessors
- (NSString *)defaultValueForField:(NSString *)field;
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"),