Permalink
Browse files

Setting large auto_increment values (> 1000) could be misinterpreted …

…as decimal values in some cases (fixes #2130)
  • Loading branch information...
dmoagx committed Jun 8, 2015
1 parent be4532c commit fb54e89b78a8d72c433db83ed435564770d7b895
@@ -15857,7 +15857,7 @@ AAEAAQAAAT0AAwAAAAEAAgAAAVIAAwAAAAEAAQAAAVMAAwAAAAIAAQABAAAAAA</bytes>
</object>
<object class="IBConnectionRecord">
<object class="IBActionConnection" key="connection">
<string key="label">resetAutoIncrementValueWasEdited:</string>
<string key="label">tableRowAutoIncrementWasEdited:</string>
<reference key="source" ref="269913528"/>
<reference key="destination" ref="735808692"/>
</object>
@@ -29569,7 +29569,7 @@ AAEAAQAAAT0AAwAAAAEAAgAAAVIAAwAAAAEAAQAAAVMAAwAAAAIAAQABAAAAAA</bytes>
<dictionary class="NSMutableDictionary" key="actions">
<string key="reloadTable:">id</string>
<string key="resetAutoIncrement:">id</string>
<string key="resetAutoIncrementValueWasEdited:">id</string>
<string key="tableRowAutoIncrementWasEdited:">id</string>
<string key="updateTableCollation:">id</string>
<string key="updateTableEncoding:">id</string>
<string key="updateTableType:">id</string>
@@ -29583,8 +29583,8 @@ AAEAAQAAAT0AAwAAAAEAAgAAAVIAAwAAAAEAAQAAAVMAAwAAAAIAAQABAAAAAA</bytes>
<string key="name">resetAutoIncrement:</string>
<string key="candidateClassName">id</string>
</object>
<object class="IBActionInfo" key="resetAutoIncrementValueWasEdited:">
<string key="name">resetAutoIncrementValueWasEdited:</string>
<object class="IBActionInfo" key="tableRowAutoIncrementWasEdited:">
<string key="name">tableRowAutoIncrementWasEdited:</string>
<string key="candidateClassName">id</string>
</object>
<object class="IBActionInfo" key="updateTableCollation:">
@@ -29719,7 +29719,7 @@ AAEAAQAAAT0AAwAAAAEAAgAAAVIAAwAAAAEAAQAAAVMAAwAAAAIAAQABAAAAAA</bytes>
<dictionary class="NSMutableDictionary" key="actions">
<string key="reloadTable:">id</string>
<string key="resetAutoIncrement:">id</string>
<string key="resetAutoIncrementValueWasEdited:">id</string>
<string key="tableRowAutoIncrementWasEdited:">id</string>
<string key="updateTableCollation:">id</string>
<string key="updateTableEncoding:">id</string>
<string key="updateTableType:">id</string>
@@ -29733,8 +29733,8 @@ AAEAAQAAAT0AAwAAAAEAAgAAAVIAAwAAAAEAAQAAAVMAAwAAAAIAAQABAAAAAA</bytes>
<string key="name">resetAutoIncrement:</string>
<string key="candidateClassName">id</string>
</object>
<object class="IBActionInfo" key="resetAutoIncrementValueWasEdited:">
<string key="name">resetAutoIncrementValueWasEdited:</string>
<object class="IBActionInfo" key="tableRowAutoIncrementWasEdited:">
<string key="name">tableRowAutoIncrementWasEdited:</string>
<string key="candidateClassName">id</string>
</object>
<object class="IBActionInfo" key="updateTableCollation:">
@@ -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;
@@ -216,10 +216,11 @@ - (IBAction)resetAutoIncrement:(id)sender
}
}
- (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
@@ -2038,7 +2038,7 @@ - (void)removeRowSheetDidEnd:(NSAlert *)alert returnCode:(NSInteger)returnCode c
// 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
@@ -575,6 +575,7 @@ - (NSDictionary *) informationForTable:(NSString *)tableName
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")];
@@ -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;
@@ -490,7 +490,7 @@ - (IBAction)resetAutoIncrement:(id)sender
[resetAutoIncrementValue setStringValue:@"1"];
}
else if ([sender tag] == 2) {
[self setAutoIncrementTo:@"1"];
[self setAutoIncrementTo:@1];
}
#endif
}
@@ -505,11 +505,21 @@ - (void)resetAutoincrementSheetDidEnd:(NSWindow *)theSheet returnCode:(NSInteger
[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 @@ - (IBAction)closeSheet:(id)sender
*
* @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 @@ - (void)setAutoIncrementTo:(NSString*)valueAsString
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"),

0 comments on commit fb54e89

Please sign in to comment.