From b91ee5c9ee79e2407b85155748ad35d698cca574 Mon Sep 17 00:00:00 2001 From: Bibiko Date: Fri, 26 Feb 2010 22:41:56 +0000 Subject: =?UTF-8?q?=E2=80=A2=20REPAIR,=20OPTIMIZE,=20ANALYZE,=20FLUSH,=20C?= =?UTF-8?q?HECKSUM=20now=20can=20be=20applied=20to=20more=20than=20one=20s?= =?UTF-8?q?elected=20item=20in=20the=20TablesList;=20if=20no=20error=20ale?= =?UTF-8?q?rt=20OK,=20if=20not=20or=20for=20CHECKSUM=20list=20the=20output?= =?UTF-8?q?=20in=20a=20table=20view=20-=20while=20sheet=20is=20open=20show?= =?UTF-8?q?ing=20the=20accessory=20table=20user=20can=20press=20=E2=8C=98C?= =?UTF-8?q?=20for=20copying=20it=20-=20added=20missing=20NSLocalizeStrings?= =?UTF-8?q?=20=E2=80=A2=20fixed=20a=20tiny=20issue=20for=20$SP=5FSELECTED?= =?UTF-8?q?=5FTABLES?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Interfaces/English.lproj/DBView.xib | 122 ++++++++---- Source/CMTextView.m | 2 +- Source/TableDocument.h | 2 + Source/TableDocument.m | 369 +++++++++++++++++++++++++++--------- Source/TablesList.m | 17 ++ 5 files changed, 389 insertions(+), 123 deletions(-) diff --git a/Interfaces/English.lproj/DBView.xib b/Interfaces/English.lproj/DBView.xib index 68f621b8..47e08691 100644 --- a/Interfaces/English.lproj/DBView.xib +++ b/Interfaces/English.lproj/DBView.xib @@ -24,7 +24,6 @@ YES - YES @@ -2144,7 +2143,7 @@ content - + 256 YES @@ -2884,6 +2883,7 @@ {{10, 7}, {706, 544}} + Content @@ -3807,7 +3807,7 @@ status - + 256 YES @@ -4610,7 +4610,6 @@ {{10, 7}, {706, 544}} - Status @@ -5445,14 +5444,14 @@ - + 134217731 YES YES YES - + @@ -8725,7 +8724,7 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 {3.40282e+38, 3.40282e+38} {213, 107} - + 256 YES @@ -8734,7 +8733,6 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 264 {{20, 233}, {140, 14}} - YES 67239424 @@ -8761,7 +8759,6 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 2322 {352, 14} - @@ -8811,7 +8808,6 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 {{1, 1}, {352, 178}} - @@ -8823,7 +8819,6 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 256 {{353, 1}, {11, 178}} - 256 _doScroller: @@ -8834,7 +8829,6 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 -2147483392 {{-100, -100}, {87, 18}} - 257 _doScroller: @@ -8844,7 +8838,6 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 {{20, 45}, {365, 180}} - 18 @@ -8856,7 +8849,6 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 257 {{314, 13}, {76, 28}} - YES 67239424 @@ -8878,7 +8870,6 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 257 {{350, -130}, {80, 28}} - YES 67239424 @@ -8897,8 +8888,6 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 {405, 267} - - {{0, 0}, {1440, 878}} {213, 129} @@ -11430,6 +11419,26 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 268 YES + + + 268 + {{270, -32}, {58, 28}} + + YES + + 67239424 + 134348800 + Copy + + + -2038284033 + 268435585 + + c + 200 + 25 + + 274 @@ -11443,7 +11452,7 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 256 - {358, 117} + {358, 139} YES @@ -11479,9 +11488,9 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 337772096 - 2048 + 133120 Text Cell - + @@ -11498,16 +11507,16 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 75628096 2048 - Status + 337772096 - 2048 + 133120 Text Cell - + @@ -11531,9 +11540,9 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 337772096 - 2048 + 133120 Text Cell - + @@ -11555,7 +11564,7 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 - 17 + 14 1388314624 @@ -11568,7 +11577,7 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 1 - {{1, 17}, {358, 117}} + {{1, 17}, {358, 139}} @@ -11611,7 +11620,7 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 - {360, 135} + {360, 157} 562 @@ -11620,10 +11629,10 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 - QSAAAEEgAABBmAAAQZgAAA + QSAAAEEgAABBgAAAQYAAAA - {360, 135} + {360, 157} NSView @@ -16140,6 +16149,22 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 6900 + + + statusTableCopyChecksum + + + + 6903 + + + + copyChecksumFromSheet: + + + + 6904 + @@ -22604,6 +22629,7 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 YES + statusTable Accessory View @@ -22712,6 +22738,20 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 + + 6901 + + + YES + + + + + + 6902 + + + @@ -24086,7 +24126,11 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 6892.IBPluginDependency 6893.IBPluginDependency 6894.IBPluginDependency + 6895.IBPluginDependency + 6896.IBPluginDependency 69.ImportedFromIB2 + 6901.IBPluginDependency + 6902.IBPluginDependency 711.IBPluginDependency 711.ImportedFromIB2 713.IBPluginDependency @@ -24896,11 +24940,11 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin - {{51, 206}, {944, 550}} + {{402, -257}, {944, 550}} com.apple.InterfaceBuilder.CocoaPlugin - {{51, 206}, {944, 550}} + {{402, -257}, {944, 550}} {{62, 352}, {845, 504}} @@ -26066,7 +26110,9 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 com.apple.InterfaceBuilder.CocoaPlugin - {{92, 444}, {360, 135}} + {{79, 571}, {360, 157}} + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin @@ -26079,6 +26125,8 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin + com.apple.InterfaceBuilder.CocoaPlugin com.apple.InterfaceBuilder.CocoaPlugin @@ -26221,7 +26269,7 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 - 6900 + 6907 @@ -28218,6 +28266,7 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 closePanelSheet: closePasswordSheet: closeSheet: + copyChecksumFromSheet: copyCreateTableSyntax: copyCreateTableSyntaxFromSheet: export: @@ -28290,6 +28339,7 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 id id id + id @@ -28332,7 +28382,9 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 sidebarGrabber spHistoryControllerInstance statusTableAccessoryView + statusTableCopyChecksum statusTableView + statusValues tableContentInstance tableDataInstance tableDumpInstance @@ -28397,6 +28449,8 @@ IGRvIHlvdSB3YW50IHRvIGFkZCBmb3IgdGhpcyBmaWVsZD8 id id id + id + id NSButton NSTableView NSSplitView diff --git a/Source/CMTextView.m b/Source/CMTextView.m index 7d140ccb..4a226ef5 100644 --- a/Source/CMTextView.m +++ b/Source/CMTextView.m @@ -1190,7 +1190,7 @@ NSInteger alphabeticSort(id string1, id string2, void *reverse) if([selTables count]) [theHintString replaceCharactersInRange:r withString:[selTables componentsJoinedAndBacktickQuoted]]; else - [theHintString replaceCharactersInRange:r withString:@""]; + [theHintString replaceCharactersInRange:r withString:@"$SP_SELECTED_TABLE"]; } [theHintString flushCachedRegexData]; } diff --git a/Source/TableDocument.h b/Source/TableDocument.h index 74aa3402..e897ed36 100644 --- a/Source/TableDocument.h +++ b/Source/TableDocument.h @@ -52,6 +52,7 @@ IBOutlet id statusTableAccessoryView; IBOutlet id statusTableView; + IBOutlet id statusTableCopyChecksum; IBOutlet SPUserManager *userManagerInstance; @@ -243,6 +244,7 @@ - (IBAction)closePasswordSheet:(id)sender; - (IBAction)backForwardInHistory:(id)sender; - (IBAction)showUserManager:(id)sender; +- (IBAction)copyChecksumFromSheet:(id)sender; - (void)showConsole:(id)sender; diff --git a/Source/TableDocument.m b/Source/TableDocument.m index d940e39a..69e3a337 100644 --- a/Source/TableDocument.m +++ b/Source/TableDocument.m @@ -1929,8 +1929,6 @@ [alert setAccessoryView:statusTableAccessoryView]; [alert beginSheetModalForWindow:tableWindow modalDelegate:self didEndSelector:@selector(sheetDidEnd:returnCode:contextInfo:) contextInfo:@"statusError"]; } - - } /** @@ -1938,17 +1936,26 @@ */ - (IBAction)analyzeTable:(id)sender { - MCPResult *theResult = [mySQLConnection queryString:[NSString stringWithFormat:@"ANALYZE TABLE %@", [[self table] backtickQuotedString]]]; + + NSArray *selectedItems = [tablesListInstance selectedTableItems]; + id message = nil; + + if([selectedItems count] == 0) return; + + MCPResult *theResult = [mySQLConnection queryString:[NSString stringWithFormat:@"ANALYZE TABLE %@", [selectedItems componentsJoinedAndBacktickQuoted]]]; + + NSString *what = ([selectedItems count]>1) ? NSLocalizedString(@"selected items", @"selected items") : [NSString stringWithFormat:@"%@ '%@'", NSLocalizedString(@"table", @"table"), [self table]]; // Check for errors, only displaying if the connection hasn't been terminated if (![[mySQLConnection getLastErrorMessage] isEqualToString:@""]) { + NSString *mText = ([selectedItems count]>1) ? NSLocalizedString(@"Unable to analyze selected items", @"unable to analyze selected items message") : NSLocalizedString(@"Unable to analyze table", @"unable to analyze table message"); if ([mySQLConnection isConnected]) { - [[NSAlert alertWithMessageText:@"Unable to analyze table" + [[NSAlert alertWithMessageText:mText defaultButton:@"OK" alternateButton:nil otherButton:nil - informativeTextWithFormat:[NSString stringWithFormat:@"An error occurred while trying to analyze the table '%@'. Please try again.\n\n%@", [self table], [mySQLConnection getLastErrorMessage]]] + informativeTextWithFormat:[NSString stringWithFormat:NSLocalizedString(@"An error occurred while analyzing the %@.\n\nMySQL said:%@",@"an error occurred while analyzing the %@.\n\nMySQL said:%@"), what, [mySQLConnection getLastErrorMessage]]] beginSheetModalForWindow:tableWindow modalDelegate:self didEndSelector:NULL @@ -1958,24 +1965,47 @@ return; } - // Process result - NSDictionary *result = [[theResult fetch2DResultAsType:MCPTypeDictionary] lastObject]; + NSDictionary *result = [theResult fetch2DResultAsType:MCPTypeDictionary]; + BOOL statusOK = YES; + for(id res in result) { + if(![[res objectForKey:@"Msg_type"] isEqualToString:@"status"]) { + statusOK = NO; + break; + } + } - NSString *message = @""; + // Process result + if([selectedItems count] == 1) { + message = @""; - message = ([[result objectForKey:@"Msg_type"] isEqualToString:@"status"]) ? @"Successfully analyzed table" : @"Analyze table failed."; + NSDictionary *lastresult = [[theResult fetch2DResultAsType:MCPTypeDictionary] lastObject]; - message = [NSString stringWithFormat:@"%@\n\nMySQL said: %@", message, [result objectForKey:@"Msg_text"]]; + message = ([[lastresult objectForKey:@"Msg_type"] isEqualToString:@"status"]) ? NSLocalizedString(@"Successfully analyzed table.",@"analyze table successfully passed message") : NSLocalizedString(@"Analyze table failed.", @"analyze table failed message"); - [[NSAlert alertWithMessageText:[NSString stringWithFormat:@"Analyze table '%@'", [self table]] - defaultButton:@"OK" - alternateButton:nil - otherButton:nil - informativeTextWithFormat:message] - beginSheetModalForWindow:tableWindow - modalDelegate:self - didEndSelector:NULL - contextInfo:NULL]; + message = [NSString stringWithFormat:@"%@\n\nMySQL said: %@", message, [lastresult objectForKey:@"Msg_text"]]; + } else if(statusOK) { + message = NSLocalizedString(@"Successfully analyzed all selected items.",@"successfully analyzed all selected items message"); + } + + if(message) { + [[NSAlert alertWithMessageText:[NSString stringWithFormat:@"Analyze %@", what] + defaultButton:@"OK" + alternateButton:nil + otherButton:nil + informativeTextWithFormat:message] + beginSheetModalForWindow:tableWindow + modalDelegate:self + didEndSelector:NULL + contextInfo:NULL]; + } else { + message = NSLocalizedString(@"MySQL said:",@"mysql said message"); + statusValues = [result retain]; + NSAlert *alert = [[NSAlert new] autorelease]; + [alert setInformativeText:message]; + [alert setMessageText:NSLocalizedString(@"Error while analyzing selected items", @"error while analyzing selected items message")]; + [alert setAccessoryView:statusTableAccessoryView]; + [alert beginSheetModalForWindow:tableWindow modalDelegate:self didEndSelector:@selector(sheetDidEnd:returnCode:contextInfo:) contextInfo:@"statusError"]; + } } /** @@ -1983,17 +2013,26 @@ */ - (IBAction)optimizeTable:(id)sender { - MCPResult *theResult = [mySQLConnection queryString:[NSString stringWithFormat:@"OPTIMIZE TABLE %@", [[self table] backtickQuotedString]]]; + + NSArray *selectedItems = [tablesListInstance selectedTableItems]; + id message = nil; + + if([selectedItems count] == 0) return; + + MCPResult *theResult = [mySQLConnection queryString:[NSString stringWithFormat:@"OPTIMIZE TABLE %@", [selectedItems componentsJoinedAndBacktickQuoted]]]; + + NSString *what = ([selectedItems count]>1) ? NSLocalizedString(@"selected items", @"selected items") : [NSString stringWithFormat:@"%@ '%@'", NSLocalizedString(@"table", @"table"), [self table]]; // Check for errors, only displaying if the connection hasn't been terminated if (![[mySQLConnection getLastErrorMessage] isEqualToString:@""]) { + NSString *mText = ([selectedItems count]>1) ? NSLocalizedString(@"Unable to optimze selected items", @"unable to optimze selected items message") : NSLocalizedString(@"Unable to optimze table", @"unable to optimze table message"); if ([mySQLConnection isConnected]) { - [[NSAlert alertWithMessageText:@"Unable to optimize table" + [[NSAlert alertWithMessageText:mText defaultButton:@"OK" alternateButton:nil otherButton:nil - informativeTextWithFormat:[NSString stringWithFormat:@"An error occurred while trying to optimize the table '%@'. Please try again.\n\n%@", [self table], [mySQLConnection getLastErrorMessage]]] + informativeTextWithFormat:[NSString stringWithFormat:NSLocalizedString(@"An error occurred while optimzing the %@.\n\nMySQL said:%@",@"an error occurred while trying to optimze the %@.\n\nMySQL said:%@"), what, [mySQLConnection getLastErrorMessage]]] beginSheetModalForWindow:tableWindow modalDelegate:self didEndSelector:NULL @@ -2003,24 +2042,47 @@ return; } + NSDictionary *result = [theResult fetch2DResultAsType:MCPTypeDictionary]; + BOOL statusOK = YES; + for(id res in result) { + if(![[res objectForKey:@"Msg_type"] isEqualToString:@"status"]) { + statusOK = NO; + break; + } + } + // Process result - NSDictionary *result = [[theResult fetch2DResultAsType:MCPTypeDictionary] lastObject]; + if([selectedItems count] == 1) { + message = @""; - NSString *message = @""; + NSDictionary *lastresult = [[theResult fetch2DResultAsType:MCPTypeDictionary] lastObject]; - message = ([[result objectForKey:@"Msg_type"] isEqualToString:@"status"]) ? @"Successfully optimized table" : @"Optimize table failed."; + message = ([[lastresult objectForKey:@"Msg_type"] isEqualToString:@"status"]) ? NSLocalizedString(@"Successfully optimized table.",@"optimize table successfully passed message") : NSLocalizedString(@"Optimize table failed.", @"optimize table failed message"); - message = [NSString stringWithFormat:@"%@\n\nMySQL said: %@", message, [result objectForKey:@"Msg_text"]]; + message = [NSString stringWithFormat:@"%@\n\nMySQL said: %@", message, [lastresult objectForKey:@"Msg_text"]]; + } else if(statusOK) { + message = NSLocalizedString(@"Successfully optimized all selected items.",@"successfully optimized all selected items message"); + } - [[NSAlert alertWithMessageText:[NSString stringWithFormat:@"Optimize table '%@'", [self table]] - defaultButton:@"OK" - alternateButton:nil - otherButton:nil - informativeTextWithFormat:message] - beginSheetModalForWindow:tableWindow - modalDelegate:self - didEndSelector:NULL - contextInfo:NULL]; + if(message) { + [[NSAlert alertWithMessageText:[NSString stringWithFormat:@"Optimize %@", what] + defaultButton:@"OK" + alternateButton:nil + otherButton:nil + informativeTextWithFormat:message] + beginSheetModalForWindow:tableWindow + modalDelegate:self + didEndSelector:NULL + contextInfo:NULL]; + } else { + message = NSLocalizedString(@"MySQL said:",@"mysql said message"); + statusValues = [result retain]; + NSAlert *alert = [[NSAlert new] autorelease]; + [alert setInformativeText:message]; + [alert setMessageText:NSLocalizedString(@"Error while optimizing selected items", @"error while optimizing selected items message")]; + [alert setAccessoryView:statusTableAccessoryView]; + [alert beginSheetModalForWindow:tableWindow modalDelegate:self didEndSelector:@selector(sheetDidEnd:returnCode:contextInfo:) contextInfo:@"statusError"]; + } } /** @@ -2028,17 +2090,25 @@ */ - (IBAction)repairTable:(id)sender { - MCPResult *theResult = [mySQLConnection queryString:[NSString stringWithFormat:@"REPAIR TABLE %@", [[self table] backtickQuotedString]]]; + NSArray *selectedItems = [tablesListInstance selectedTableItems]; + id message = nil; + + if([selectedItems count] == 0) return; + + MCPResult *theResult = [mySQLConnection queryString:[NSString stringWithFormat:@"REPAIR TABLE %@", [selectedItems componentsJoinedAndBacktickQuoted]]]; + + NSString *what = ([selectedItems count]>1) ? NSLocalizedString(@"selected items", @"selected items") : [NSString stringWithFormat:@"%@ '%@'", NSLocalizedString(@"table", @"table"), [self table]]; // Check for errors, only displaying if the connection hasn't been terminated if (![[mySQLConnection getLastErrorMessage] isEqualToString:@""]) { + NSString *mText = ([selectedItems count]>1) ? NSLocalizedString(@"Unable to repair selected items", @"unable to repair selected items message") : NSLocalizedString(@"Unable to repair table", @"unable to repair table message"); if ([mySQLConnection isConnected]) { - [[NSAlert alertWithMessageText:@"Unable to repair table" + [[NSAlert alertWithMessageText:mText defaultButton:@"OK" alternateButton:nil otherButton:nil - informativeTextWithFormat:[NSString stringWithFormat:@"An error occurred while trying to repair the table '%@'. Please try again.\n\n%@", [self table], [mySQLConnection getLastErrorMessage]]] + informativeTextWithFormat:[NSString stringWithFormat:NSLocalizedString(@"An error occurred while repairing the %@.\n\nMySQL said:%@",@"an error occurred while trying to repair the %@.\n\nMySQL said:%@"), what, [mySQLConnection getLastErrorMessage]]] beginSheetModalForWindow:tableWindow modalDelegate:self didEndSelector:NULL @@ -2048,24 +2118,47 @@ return; } + NSDictionary *result = [theResult fetch2DResultAsType:MCPTypeDictionary]; + BOOL statusOK = YES; + for(id res in result) { + if(![[res objectForKey:@"Msg_type"] isEqualToString:@"status"]) { + statusOK = NO; + break; + } + } + // Process result - NSDictionary *result = [[theResult fetch2DResultAsType:MCPTypeDictionary] lastObject]; + if([selectedItems count] == 1) { + message = @""; - NSString *message = @""; + NSDictionary *lastresult = [[theResult fetch2DResultAsType:MCPTypeDictionary] lastObject]; - message = ([[result objectForKey:@"Msg_type"] isEqualToString:@"status"]) ? @"Successfully repaired table" : @"Repair table failed."; + message = ([[lastresult objectForKey:@"Msg_type"] isEqualToString:@"status"]) ? NSLocalizedString(@"Successfully repaired table.",@"repair table successfully passed message") : NSLocalizedString(@"Repair table failed.", @"repair table failed message"); - message = [NSString stringWithFormat:@"%@\n\nMySQL said: %@", message, [result objectForKey:@"Msg_text"]]; + message = [NSString stringWithFormat:@"%@\n\nMySQL said: %@", message, [lastresult objectForKey:@"Msg_text"]]; + } else if(statusOK) { + message = NSLocalizedString(@"Successfully repaired all selected items.",@"successfully repaired all selected items message"); + } - [[NSAlert alertWithMessageText:[NSString stringWithFormat:@"Repair table '%@'", [self table]] - defaultButton:@"OK" - alternateButton:nil - otherButton:nil - informativeTextWithFormat:message] - beginSheetModalForWindow:tableWindow - modalDelegate:self - didEndSelector:NULL - contextInfo:NULL]; + if(message) { + [[NSAlert alertWithMessageText:[NSString stringWithFormat:@"Repair %@", what] + defaultButton:@"OK" + alternateButton:nil + otherButton:nil + informativeTextWithFormat:message] + beginSheetModalForWindow:tableWindow + modalDelegate:self + didEndSelector:NULL + contextInfo:NULL]; + } else { + message = NSLocalizedString(@"MySQL said:",@"mysql said message"); + statusValues = [result retain]; + NSAlert *alert = [[NSAlert new] autorelease]; + [alert setInformativeText:message]; + [alert setMessageText:NSLocalizedString(@"Error while repairing selected items", @"error while repairing selected items message")]; + [alert setAccessoryView:statusTableAccessoryView]; + [alert beginSheetModalForWindow:tableWindow modalDelegate:self didEndSelector:@selector(sheetDidEnd:returnCode:contextInfo:) contextInfo:@"statusError"]; + } } /** @@ -2073,35 +2166,75 @@ */ - (IBAction)flushTable:(id)sender { - [mySQLConnection queryString:[NSString stringWithFormat:@"FLUSH TABLE %@", [[self table] backtickQuotedString]]]; + NSArray *selectedItems = [tablesListInstance selectedTableItems]; + id message = nil; + + if([selectedItems count] == 0) return; + + MCPResult *theResult = [mySQLConnection queryString:[NSString stringWithFormat:@"FLUSH TABLE %@", [selectedItems componentsJoinedAndBacktickQuoted]]]; + + NSString *what = ([selectedItems count]>1) ? NSLocalizedString(@"selected items", @"selected items") : [NSString stringWithFormat:@"%@ '%@'", NSLocalizedString(@"table", @"table"), [self table]]; // Check for errors, only displaying if the connection hasn't been terminated if (![[mySQLConnection getLastErrorMessage] isEqualToString:@""]) { + NSString *mText = ([selectedItems count]>1) ? NSLocalizedString(@"Unable to flush selected items", @"unable to flush selected items message") : NSLocalizedString(@"Unable to flush table", @"unable to flush table message"); if ([mySQLConnection isConnected]) { - [[NSAlert alertWithMessageText:@"Unable to flush table" + [[NSAlert alertWithMessageText:mText defaultButton:@"OK" alternateButton:nil otherButton:nil - informativeTextWithFormat:[NSString stringWithFormat:@"An error occurred while trying to flush the table '%@'. Please try again.\n\n%@", [self table], [mySQLConnection getLastErrorMessage]]] + informativeTextWithFormat:[NSString stringWithFormat:NSLocalizedString(@"An error occurred while flushing the %@.\n\nMySQL said:%@",@"an error occurred while trying to flush the %@.\n\nMySQL said:%@"), what, [mySQLConnection getLastErrorMessage]]] beginSheetModalForWindow:tableWindow modalDelegate:self didEndSelector:NULL - contextInfo:NULL]; + contextInfo:NULL]; } return; } - [[NSAlert alertWithMessageText:[NSString stringWithFormat:@"Flush table '%@'", [self table]] - defaultButton:@"OK" - alternateButton:nil - otherButton:nil - informativeTextWithFormat:@"Table was successfully flushed"] - beginSheetModalForWindow:tableWindow - modalDelegate:self - didEndSelector:NULL - contextInfo:NULL]; + NSDictionary *result = [theResult fetch2DResultAsType:MCPTypeDictionary]; + BOOL statusOK = YES; + for(id res in result) { + if(![[res objectForKey:@"Msg_type"] isEqualToString:@"status"]) { + statusOK = NO; + break; + } + } + + // Process result + if([selectedItems count] == 1) { + message = @""; + + NSDictionary *lastresult = [[theResult fetch2DResultAsType:MCPTypeDictionary] lastObject]; + + message = ([[lastresult objectForKey:@"Msg_type"] isEqualToString:@"status"]) ? NSLocalizedString(@"Successfully flushed table.",@"flush table successfully passed message") : NSLocalizedString(@"Flush table failed.", @"flush table failed message"); + + message = [NSString stringWithFormat:@"%@\n\nMySQL said: %@", message, [lastresult objectForKey:@"Msg_text"]]; + } else if(statusOK) { + message = NSLocalizedString(@"Successfully flushed all selected items.",@"successfully flushed all selected items message"); + } + + if(message) { + [[NSAlert alertWithMessageText:[NSString stringWithFormat:@"Flush %@", what] + defaultButton:@"OK" + alternateButton:nil + otherButton:nil + informativeTextWithFormat:message] + beginSheetModalForWindow:tableWindow + modalDelegate:self + didEndSelector:NULL + contextInfo:NULL]; + } else { + message = NSLocalizedString(@"MySQL said:",@"mysql said message"); + statusValues = [result retain]; + NSAlert *alert = [[NSAlert new] autorelease]; + [alert setInformativeText:message]; + [alert setMessageText:NSLocalizedString(@"Error while flushing selected items", @"error while flushing selected items message")]; + [alert setAccessoryView:statusTableAccessoryView]; + [alert beginSheetModalForWindow:tableWindow modalDelegate:self didEndSelector:@selector(sheetDidEnd:returnCode:contextInfo:) contextInfo:@"statusError"]; + } } /** @@ -2109,37 +2242,54 @@ */ - (IBAction)checksumTable:(id)sender { - MCPResult *theResult = [mySQLConnection queryString:[NSString stringWithFormat:@"CHECKSUM TABLE %@", [[self table] backtickQuotedString]]]; + NSArray *selectedItems = [tablesListInstance selectedTableItems]; + id message = nil; + + if([selectedItems count] == 0) return; + + MCPResult *theResult = [mySQLConnection queryString:[NSString stringWithFormat:@"CHECKSUM TABLE %@", [selectedItems componentsJoinedAndBacktickQuoted]]]; + + NSString *what = ([selectedItems count]>1) ? NSLocalizedString(@"selected items", @"selected items") : [NSString stringWithFormat:@"%@ '%@'", NSLocalizedString(@"table", @"table"), [self table]]; // Check for errors, only displaying if the connection hasn't been terminated if (![[mySQLConnection getLastErrorMessage] isEqualToString:@""]) { if ([mySQLConnection isConnected]) { - [[NSAlert alertWithMessageText:@"Unable to perform checksum" + [[NSAlert alertWithMessageText:NSLocalizedString(@"Unable to perform the checksum", @"unable to perform the checksum") defaultButton:@"OK" alternateButton:nil otherButton:nil - informativeTextWithFormat:[NSString stringWithFormat:@"An error occurred while performing the checksum on table '%@'. Please try again.\n\n%@", [self table], [mySQLConnection getLastErrorMessage]]] + informativeTextWithFormat:[NSString stringWithFormat:NSLocalizedString(@"An error occurred while performing the checksum on %@.\n\nMySQL said:%@",@"an error occurred while performing the checksum on the %@.\n\nMySQL said:%@"), what, [mySQLConnection getLastErrorMessage]]] beginSheetModalForWindow:tableWindow modalDelegate:self didEndSelector:NULL contextInfo:NULL]; } + return; } // Process result - NSString *result = [[[theResult fetch2DResultAsType:MCPTypeDictionary] lastObject] objectForKey:@"Checksum"]; - - [[NSAlert alertWithMessageText:[NSString stringWithFormat:@"Checksum table '%@'", [self table]] - defaultButton:@"OK" - alternateButton:nil - otherButton:nil - informativeTextWithFormat:[NSString stringWithFormat:@"Table checksum: %@", result]] - beginSheetModalForWindow:tableWindow - modalDelegate:self - didEndSelector:NULL - contextInfo:NULL]; + if([selectedItems count] == 1) { + message = [[[theResult fetch2DResultAsType:MCPTypeDictionary] lastObject] objectForKey:@"Checksum"]; + [[NSAlert alertWithMessageText:[NSString stringWithFormat:NSLocalizedString(@"Checksum %@",@"checksum %@ message"), what] + defaultButton:@"OK" + alternateButton:nil + otherButton:nil + informativeTextWithFormat:[NSString stringWithFormat:NSLocalizedString(@"Table checksum: %@",@"table checksum: %@"), message]] + beginSheetModalForWindow:tableWindow + modalDelegate:self + didEndSelector:NULL + contextInfo:NULL]; + } else { + NSDictionary *result = [theResult fetch2DResultAsType:MCPTypeDictionary]; + statusValues = [result retain]; + NSAlert *alert = [[NSAlert new] autorelease]; + [alert setInformativeText:[NSString stringWithFormat:NSLocalizedString(@"Checksums of %@",@"Checksums of %@ message"), what]]; + [alert setMessageText:NSLocalizedString(@"Table checksum",@"table checksum message")]; + [alert setAccessoryView:statusTableAccessoryView]; + [alert beginSheetModalForWindow:tableWindow modalDelegate:self didEndSelector:@selector(sheetDidEnd:returnCode:contextInfo:) contextInfo:@"statusError"]; + } } /** @@ -2984,17 +3134,18 @@ // table menu items if ([menuItem action] == @selector(showCreateTableSyntax:) || - [menuItem action] == @selector(copyCreateTableSyntax:) || - [menuItem action] == @selector(analyzeTable:) || - [menuItem action] == @selector(optimizeTable:) || - [menuItem action] == @selector(repairTable:) || - [menuItem action] == @selector(flushTable:) || - [menuItem action] == @selector(checksumTable:)) + [menuItem action] == @selector(copyCreateTableSyntax:)) { return ([self table] != nil && [[self table] isNotEqualTo:@""]); } - if ([menuItem action] == @selector(checkTable:)) { + if ([menuItem action] == @selector(analyzeTable:) || + [menuItem action] == @selector(optimizeTable:) || + [menuItem action] == @selector(repairTable:) || + [menuItem action] == @selector(flushTable:) || + [menuItem action] == @selector(checkTable:) || + [menuItem action] == @selector(checksumTable:)) + { return ([[[tablesListInstance valueForKeyPath:@"tablesListView"] selectedRowIndexes] count]) ? YES:NO; } @@ -3745,13 +3896,27 @@ { if(statusTableView && aTableView == statusTableView && rowIndex < [statusValues count]) { if ([[aTableColumn identifier] isEqualToString:@"table_name"]) { - return [[statusValues objectAtIndex:rowIndex] objectForKey:@"Table"]; + if([[statusValues objectAtIndex:rowIndex] objectForKey:@"table_name"]) + return [[statusValues objectAtIndex:rowIndex] objectForKey:@"table_name"]; + else if([[statusValues objectAtIndex:rowIndex] objectForKey:@"Table"]) + return [[statusValues objectAtIndex:rowIndex] objectForKey:@"Table"]; + return @""; } else if ([[aTableColumn identifier] isEqualToString:@"msg_status"]) { - return [[statusValues objectAtIndex:rowIndex] objectForKey:@"Msg_type"]; + if([[statusValues objectAtIndex:rowIndex] objectForKey:@"Msg_type"]) + return [[[statusValues objectAtIndex:rowIndex] objectForKey:@"Msg_type"] capitalizedString]; + return @""; } else if ([[aTableColumn identifier] isEqualToString:@"msg_text"]) { - return [[statusValues objectAtIndex:rowIndex] objectForKey:@"Msg_text"]; + if([[statusValues objectAtIndex:rowIndex] objectForKey:@"Msg_text"]) { + [[aTableColumn headerCell] setStringValue:NSLocalizedString(@"Message",@"message column title")]; + return [[statusValues objectAtIndex:rowIndex] objectForKey:@"Msg_text"]; + } + else if([[statusValues objectAtIndex:rowIndex] objectForKey:@"Checksum"]) { + [[aTableColumn headerCell] setStringValue:@"Checksum"]; + return [[statusValues objectAtIndex:rowIndex] objectForKey:@"Checksum"]; + } + return @""; } } return nil; @@ -3762,6 +3927,34 @@ return NO; } + +#pragma mark - +#pragma mark status accessory view + +- (IBAction)copyChecksumFromSheet:(id)sender +{ + NSMutableString *tmp = [NSMutableString string]; + for(id row in statusValues) + if([row objectForKey:@"Msg_type"]) + [tmp appendFormat:@"%@\t%@\t%@\n", [[row objectForKey:@"Table"] description], + [[row objectForKey:@"Msg_type"] description], + [[row objectForKey:@"Msg_text"] description]]; + else + [tmp appendFormat:@"%@\t%@\n", [[row objectForKey:@"Table"] description], + [[row objectForKey:@"Checksum"] description]]; + if ( [tmp length] ) + { + NSPasteboard *pb = [NSPasteboard generalPasteboard]; + + [pb declareTypes:[NSArray arrayWithObjects: NSTabularTextPboardType, + NSStringPboardType, nil] + owner:nil]; + + [pb setString:tmp forType:NSStringPboardType]; + [pb setString:tmp forType:NSTabularTextPboardType]; + } +} + #pragma mark - /** diff --git a/Source/TablesList.m b/Source/TablesList.m index 3ca55f43..e9c07510 100644 --- a/Source/TablesList.m +++ b/Source/TablesList.m @@ -824,6 +824,19 @@ NSMenu *tableSubMenu = [[[NSApp mainMenu] itemWithTitle:@"Table"] submenu]; [[tableSubMenu itemAtIndex:3] setTitle:NSLocalizedString(@"Check Selected Items", @"check selected items menu item")]; + [[tableSubMenu itemAtIndex:4] setTitle:NSLocalizedString(@"Repair Selected Items", @"repair selected items menu item")]; + [[tableSubMenu itemAtIndex:6] setTitle:NSLocalizedString(@"Analyze Selected Items", @"analyze selected items menu item")]; + [[tableSubMenu itemAtIndex:7] setTitle:NSLocalizedString(@"Optimize Selected Items", @"optimize selected items menu item")]; + [[tableSubMenu itemAtIndex:8] setTitle:NSLocalizedString(@"Flush Selected Items", @"flush selected items menu item")]; + [[tableSubMenu itemAtIndex:9] setTitle:NSLocalizedString(@"Checksum Selected Items", @"checksum selected items menu item")]; + [[tableSubMenu itemAtIndex:2] setHidden:NO]; + [[tableSubMenu itemAtIndex:3] setHidden:NO]; + [[tableSubMenu itemAtIndex:4] setHidden:NO]; + [[tableSubMenu itemAtIndex:5] setHidden:NO]; + [[tableSubMenu itemAtIndex:6] setHidden:NO]; + [[tableSubMenu itemAtIndex:7] setHidden:NO]; + [[tableSubMenu itemAtIndex:8] setHidden:NO]; + [[tableSubMenu itemAtIndex:9] setHidden:NO]; // set window title @@ -898,12 +911,16 @@ [[tableSubMenu itemAtIndex:3] setHidden:NO]; [[tableSubMenu itemAtIndex:3] setTitle:NSLocalizedString(@"Check Table", @"check table menu item")]; [[tableSubMenu itemAtIndex:4] setHidden:NO]; + [[tableSubMenu itemAtIndex:4] setTitle:NSLocalizedString(@"Repair Table", @"repair table menu item")]; [[tableSubMenu itemAtIndex:5] setHidden:NO]; // divider [[tableSubMenu itemAtIndex:6] setHidden:NO]; + [[tableSubMenu itemAtIndex:6] setTitle:NSLocalizedString(@"Analyze Table", @"analyze table menu item")]; [[tableSubMenu itemAtIndex:7] setHidden:NO]; + [[tableSubMenu itemAtIndex:7] setTitle:NSLocalizedString(@"Optimize Table", @"optimize table menu item")]; [[tableSubMenu itemAtIndex:8] setHidden:NO]; [[tableSubMenu itemAtIndex:8] setTitle:NSLocalizedString(@"Flush Table", @"flush table menu item")]; [[tableSubMenu itemAtIndex:9] setHidden:NO]; + [[tableSubMenu itemAtIndex:9] setTitle:NSLocalizedString(@"Checksum Table", @"checksum table menu item")]; [renameTableMenuItem setHidden:NO]; [renameTableMenuItem setTitle:NSLocalizedString(@"Rename Table...", @"rename table menu title")]; -- cgit v1.2.3