From 0d39a10771ae048d49d413ac1baf1d8f485190e0 Mon Sep 17 00:00:00 2001 From: Bibiko Date: Mon, 22 Feb 2010 17:25:16 +0000 Subject: =?UTF-8?q?=E2=80=A2=20implemented=20chance=20to=20reset=20AUTO=5F?= =?UTF-8?q?INCREMENT=20of=20the=20PRIMARY=20KEY=20field=20in=20Structure?= =?UTF-8?q?=20Pane=20via=20right-click=20at=20the=20index=20tableView=20-?= =?UTF-8?q?=20implementation=20in=20the=20Table=20Info=20follows=20soon?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Source/TableDocument.m | 3 ++- Source/TableSource.h | 1 + Source/TableSource.m | 21 ++++++++++++++++++--- 3 files changed, 21 insertions(+), 4 deletions(-) (limited to 'Source') diff --git a/Source/TableDocument.m b/Source/TableDocument.m index b8261a8e..1565a477 100644 --- a/Source/TableDocument.m +++ b/Source/TableDocument.m @@ -3613,7 +3613,7 @@ - (NSRect)window:(NSWindow *)window willPositionSheet:(NSWindow *)sheet usingRect:(NSRect)rect { - // Locate the sheet "Reset Auto Increment" just beneath the chosen index row + // Locate the sheet "Reset Auto Increment" just centered beneath the chosen index row if([[sheet title] isEqualToString:@"Reset Auto Increment"]) { id it = [tableSourceInstance valueForKeyPath:@"indexView"]; @@ -3622,6 +3622,7 @@ NSRect rowrect = [it rectOfRow:[it selectedRow]]; rowrect.size.width = mwrect.size.width - ltrect.size.width; rowrect.origin.y -= [it rowHeight]/2.0f+2; + rowrect.origin.x -= 8; return [it convertRect:rowrect toView:nil]; } else diff --git a/Source/TableSource.h b/Source/TableSource.h index e09dd16b..6904b875 100644 --- a/Source/TableSource.h +++ b/Source/TableSource.h @@ -31,6 +31,7 @@ IBOutlet id tablesListInstance; IBOutlet id tableDataInstance; IBOutlet id tableDocumentInstance; + IBOutlet id tableInfoInstance; IBOutlet id tableWindow; IBOutlet id indexSheet; 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 -- cgit v1.2.3