aboutsummaryrefslogtreecommitdiffstats
path: root/Source/TableSource.m
diff options
context:
space:
mode:
authorBibiko <bibiko@eva.mpg.de>2010-02-22 17:25:16 +0000
committerBibiko <bibiko@eva.mpg.de>2010-02-22 17:25:16 +0000
commit0d39a10771ae048d49d413ac1baf1d8f485190e0 (patch)
tree5aa39da9173d24caa1f8f78c31e8c58905cbddc4 /Source/TableSource.m
parent6d018a4e2eb0505776092e6f626d70b1ad3d5295 (diff)
downloadsequelpro-0d39a10771ae048d49d413ac1baf1d8f485190e0.tar.gz
sequelpro-0d39a10771ae048d49d413ac1baf1d8f485190e0.tar.bz2
sequelpro-0d39a10771ae048d49d413ac1baf1d8f485190e0.zip
• implemented chance to reset AUTO_INCREMENT of the PRIMARY KEY field in Structure Pane via right-click at the index tableView
- implementation in the Table Info follows soon
Diffstat (limited to 'Source/TableSource.m')
-rw-r--r--Source/TableSource.m21
1 files changed, 18 insertions, 3 deletions
diff --git a/Source/TableSource.m b/Source/TableSource.m
index f704dcec..6dd3f7fb 100644
--- a/Source/TableSource.m
+++ b/Source/TableSource.m
@@ -25,6 +25,7 @@
#import "TableSource.h"
#import "TableDocument.h"
+#import "SPTableInfo.h"
#import "TablesList.h"
#import "SPTableData.h"
#import "SPSQLParser.h"
@@ -941,8 +942,9 @@ fetches the result as an array with a dictionary for each row in it
// Reset AUTO_INCREMENT
if ([menuItem action] == @selector(resetAutoIncrement:)) {
- return NO;
- return ([indexView numberOfSelectedRows] == 1 );
+ return ([indexView numberOfSelectedRows] == 1
+ && [[indexes objectAtIndex:[indexView selectedRow]] objectForKey:@"Key_name"]
+ && [[[indexes objectAtIndex:[indexView selectedRow]] objectForKey:@"Key_name"] isEqualToString:@"PRIMARY"]);
}
return YES;
@@ -1010,7 +1012,20 @@ fetches the result as an array with a dictionary for each row in it
}
else if ([contextInfo isEqualToString:@"resetAutoIncrement"]) {
if (returnCode == NSAlertDefaultReturn) {
- // ALTER TABLE tbl_name AUTO_INCREMENT = N
+
+ [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];
+ }
}
}
else