aboutsummaryrefslogtreecommitdiffstats
path: root/Source/TableSource.m
diff options
context:
space:
mode:
Diffstat (limited to 'Source/TableSource.m')
-rw-r--r--Source/TableSource.m72
1 files changed, 51 insertions, 21 deletions
diff --git a/Source/TableSource.m b/Source/TableSource.m
index 6dd3f7fb..6004a4ac 100644
--- a/Source/TableSource.m
+++ b/Source/TableSource.m
@@ -460,14 +460,24 @@ loads aTable, put it in an array, update the tableViewColumns and reload the tab
- (IBAction)resetAutoIncrement:(id)sender
{
- // Begin the sheet
- [NSApp beginSheet:resetAutoIncrementSheet
- modalForWindow:tableWindow
- modalDelegate:self
- didEndSelector:@selector(sheetDidEnd:returnCode:contextInfo:)
- contextInfo:@"resetAutoIncrement"];
+ if([sender tag] == 1) {
- [resetAutoIncrementValue setStringValue:@"1"];
+ [resetAutoIncrementLine setHidden:YES];
+ if([[tableDocumentInstance valueForKeyPath:@"tableTabView"] indexOfTabViewItem:[[tableDocumentInstance valueForKeyPath:@"tableTabView"] selectedTabViewItem]] == 0)
+ [resetAutoIncrementLine setHidden:NO];
+
+ // Begin the sheet
+ [NSApp beginSheet:resetAutoIncrementSheet
+ modalForWindow:tableWindow
+ modalDelegate:self
+ didEndSelector:@selector(sheetDidEnd:returnCode:contextInfo:)
+ contextInfo:@"resetAutoIncrement"];
+
+ [resetAutoIncrementValue setStringValue:@"1"];
+ }
+ else if([sender tag] == 2) {
+ [self setAutoIncrementTo:@"1"];
+ }
}
@@ -566,6 +576,39 @@ closes the keySheet
[tableSourceView registerForDraggedTypes:[NSArray arrayWithObjects:@"SequelProPasteboard", nil]];
}
+- (void)setAutoIncrementTo:(NSString*)valueAsString
+{
+
+ if(valueAsString == nil || ![valueAsString length]) return;
+
+ NSString *selTable = nil;
+
+ // if selectedTable is nil try to get the name from tablesList
+ if(selectedTable == nil || ![selectedTable length])
+ selTable = [tablesListInstance tableName];
+ else
+ selTable = [NSString stringWithString:selectedTable];
+
+ if(selTable == nil || ![selTable length])
+ return;
+
+ [mySQLConnection queryString:[NSString stringWithFormat:@"ALTER TABLE %@ AUTO_INCREMENT = %@", [selTable backtickQuotedString], valueAsString]];
+
+ if (![[mySQLConnection getLastErrorMessage] isEqualToString:@""]) {
+ SPBeginAlertSheet(NSLocalizedString(@"Error", @"error"),
+ NSLocalizedString(@"OK", @"OK button"),
+ nil, nil, [NSApp mainWindow], nil, nil, nil, nil,
+ [NSString stringWithFormat:NSLocalizedString(@"An error occurred while trying to reset AUTO_INCREMENT of table '%@'.\n\nMySQL said: %@", @"error resetting auto_increment informative message"),
+ selTable, [mySQLConnection getLastErrorMessage]]);
+ } else {
+ [tableDataInstance resetAllData];
+ [tablesListInstance setStatusRequiresReload:YES];
+ [self loadTable:selectedTable];
+ [extendedTableInfoInstance loadTable:selTable];
+ [tableInfoInstance tableChanged:nil];
+ }
+}
+
/*
fetches the result as an array with a dictionary for each row in it
*/
@@ -1012,20 +1055,7 @@ fetches the result as an array with a dictionary for each row in it
}
else if ([contextInfo isEqualToString:@"resetAutoIncrement"]) {
if (returnCode == NSAlertDefaultReturn) {
-
- [mySQLConnection queryString:[NSString stringWithFormat:@"ALTER TABLE %@ AUTO_INCREMENT = %@", [selectedTable backtickQuotedString], [[resetAutoIncrementValue stringValue] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]]];
-
- if (![[mySQLConnection getLastErrorMessage] isEqualToString:@""]) {
- SPBeginAlertSheet(NSLocalizedString(@"Error", @"error"),
- NSLocalizedString(@"OK", @"OK button"),
- nil, nil, [NSApp mainWindow], nil, nil, nil, nil,
- [NSString stringWithFormat:NSLocalizedString(@"An error occurred while trying to reset AUTO_INCREMENT of table '%@'.\n\nMySQL said: %@", @"error resetting auto_increment informative message"), selectedTable, [mySQLConnection getLastErrorMessage]]);
- } else {
- [tableDataInstance resetAllData];
- [tablesListInstance setStatusRequiresReload:YES];
- [self loadTable:selectedTable];
- [tableInfoInstance tableChanged:nil];
- }
+ [self setAutoIncrementTo:[[resetAutoIncrementValue stringValue] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]]];
}
}
else