aboutsummaryrefslogtreecommitdiffstats
path: root/Source/TableSource.m
diff options
context:
space:
mode:
authorBibiko <bibiko@eva.mpg.de>2010-02-22 23:36:15 +0000
committerBibiko <bibiko@eva.mpg.de>2010-02-22 23:36:15 +0000
commitc11169058366ca679789bc82cf1b3ca8ed496967 (patch)
treee2f34bd6888ac59554b9c6df5532265d8b230c76 /Source/TableSource.m
parent0d39a10771ae048d49d413ac1baf1d8f485190e0 (diff)
downloadsequelpro-c11169058366ca679789bc82cf1b3ca8ed496967.tar.gz
sequelpro-c11169058366ca679789bc82cf1b3ca8ed496967.tar.bz2
sequelpro-c11169058366ca679789bc82cf1b3ca8ed496967.zip
• implemented chance to reset AUTO_INCREMENT of the PRIMARY KEY field in Table Info Pane via Advanced popup button and sheet (not yet optimal GUI solution)
• SPAlertSheets - ensure that this sheet becomes the keyWindow
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