diff options
author | Bibiko <bibiko@eva.mpg.de> | 2010-02-25 22:46:54 +0000 |
---|---|---|
committer | Bibiko <bibiko@eva.mpg.de> | 2010-02-25 22:46:54 +0000 |
commit | 947cb3e7725ee0e67cd0b2a22c34c5c1122d6cc3 (patch) | |
tree | a651086f83f8c98d96c72b3b624d56bd0608e4db /Source | |
parent | 429879a5060d5fe0a27794a1e53b131ab04dba91 (diff) | |
download | sequelpro-947cb3e7725ee0e67cd0b2a22c34c5c1122d6cc3.tar.gz sequelpro-947cb3e7725ee0e67cd0b2a22c34c5c1122d6cc3.tar.bz2 sequelpro-947cb3e7725ee0e67cd0b2a22c34c5c1122d6cc3.zip |
• Query Favorites:
- added snippet variable $SP_SELECTED_TABLES which inserts `table1`,`table2`, etc. (ONLY tables)
• improved "Check Table"
- now one can select more than one table to execute "CHECK TABLE table1,table2,… ; if all tables passed successfully alert OK, if not show the result as accessory table in the sheet
note: OPTIMIZE, REPAIR, FLUSH, CHECKSUM, ANALYZE follow
Diffstat (limited to 'Source')
-rw-r--r-- | Source/CMTextView.m | 13 | ||||
-rw-r--r-- | Source/CustomQuery.h | 1 | ||||
-rw-r--r-- | Source/TableDocument.h | 5 | ||||
-rw-r--r-- | Source/TableDocument.m | 108 | ||||
-rw-r--r-- | Source/TablesList.h | 2 | ||||
-rw-r--r-- | Source/TablesList.m | 34 |
6 files changed, 146 insertions, 17 deletions
diff --git a/Source/CMTextView.m b/Source/CMTextView.m index 582df6c2..7d140ccb 100644 --- a/Source/CMTextView.m +++ b/Source/CMTextView.m @@ -32,6 +32,7 @@ #import "SPConstants.h" #import "SPQueryController.h" #import "SPTooltip.h" +#import "TablesList.h" #pragma mark - #pragma mark lex init @@ -1182,6 +1183,18 @@ NSInteger alphabeticSort(id string1, id string2, void *reverse) if ([[[[self window] delegate] valueForKeyPath:@"tablesListInstance"] valueForKey:@"selectedDatabase"] != nil) currentDb = [[[[self window] delegate] valueForKeyPath:@"tablesListInstance"] valueForKeyPath:@"selectedDatabase"]; + while([theHintString isMatchedByRegex:@"(?<!\\\\)\\$SP_SELECTED_TABLES"]) { + r = [theHintString rangeOfRegex:@"(?<!\\\\)\\$SP_SELECTED_TABLES"]; + if(r.length) { + NSArray *selTables = [[[self delegate] valueForKeyPath:@"tablesListInstance"] selectedTableNames]; + if([selTables count]) + [theHintString replaceCharactersInRange:r withString:[selTables componentsJoinedAndBacktickQuoted]]; + else + [theHintString replaceCharactersInRange:r withString:@"<tables>"]; + } + [theHintString flushCachedRegexData]; + } + while([theHintString isMatchedByRegex:@"(?<!\\\\)\\$SP_SELECTED_TABLE"]) { r = [theHintString rangeOfRegex:@"(?<!\\\\)\\$SP_SELECTED_TABLE"]; if(r.length) { diff --git a/Source/CustomQuery.h b/Source/CustomQuery.h index 6650ee79..e73f70da 100644 --- a/Source/CustomQuery.h +++ b/Source/CustomQuery.h @@ -54,6 +54,7 @@ @interface CustomQuery : NSObject { IBOutlet id tableDocumentInstance; + IBOutlet id tablesListInstance; IBOutlet id tableWindow; IBOutlet id queryFavoritesButton; diff --git a/Source/TableDocument.h b/Source/TableDocument.h index 6c03e01a..74aa3402 100644 --- a/Source/TableDocument.h +++ b/Source/TableDocument.h @@ -50,6 +50,9 @@ IBOutlet id spHistoryControllerInstance; IBOutlet id exportControllerInstance; + IBOutlet id statusTableAccessoryView; + IBOutlet id statusTableView; + IBOutlet SPUserManager *userManagerInstance; IBOutlet NSSearchField *listFilterField; @@ -157,6 +160,8 @@ NSMutableDictionary *spfDocData; NSString *keyChainID; + + id statusValues; } - (NSString *)getHTMLforPrint; diff --git a/Source/TableDocument.m b/Source/TableDocument.m index 4d5c5a77..d940e39a 100644 --- a/Source/TableDocument.m +++ b/Source/TableDocument.m @@ -108,6 +108,8 @@ taskCancellationCallbackSelector = NULL; keyChainID = nil; + + statusValues = nil; } return self; @@ -1168,6 +1170,10 @@ [chooseDatabaseButton selectItemAtIndex:0]; } } + // Close error status sheet for OPTIMIZE, CHECK, REPAIR etc. + else if ([contextInfo isEqualToString:@"statusError"]) { + if(statusValues) [statusValues release]; statusValues = nil; + } } @@ -1853,17 +1859,26 @@ */ - (IBAction)checkTable:(id)sender { - MCPResult *theResult = [mySQLConnection queryString:[NSString stringWithFormat:@"CHECK TABLE %@", [[self table] backtickQuotedString]]]; + + NSArray *selectedItems = [tablesListInstance selectedTableItems]; + id message = nil; + + if([selectedItems count] == 0) return; + + MCPResult *theResult = [mySQLConnection queryString:[NSString stringWithFormat:@"CHECK 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 check selected items", @"unable to check selected items message") : NSLocalizedString(@"Unable to check table", @"unable to check table message"); if ([mySQLConnection isConnected]) { - [[NSAlert alertWithMessageText:@"Unable to check table" + [[NSAlert alertWithMessageText:mText defaultButton:@"OK" alternateButton:nil otherButton:nil - informativeTextWithFormat:[NSString stringWithFormat:@"An error occurred while trying to check the table '%@'. Please try again.\n\n%@", [self table], [mySQLConnection getLastErrorMessage]]] + informativeTextWithFormat:[NSString stringWithFormat:NSLocalizedString(@"An error occurred while trying to check the %@.\n\nMySQL said:%@",@"an error occurred while trying to check the %@.\n\nMySQL said:%@"), what, [mySQLConnection getLastErrorMessage]]] beginSheetModalForWindow:tableWindow modalDelegate:self didEndSelector:NULL @@ -1873,24 +1888,49 @@ 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"]) ? @"Check table successfully passed." : @"Check table failed."; + message = ([[lastresult objectForKey:@"Msg_type"] isEqualToString:@"status"]) ? NSLocalizedString(@"Check table successfully passed.",@"check table successfully passed message") : NSLocalizedString(@"Check table failed.", @"check table failed message"); + + message = [NSString stringWithFormat:@"%@\n\nMySQL said: %@", message, [lastresult objectForKey:@"Msg_text"]]; + } else if(statusOK) { + message = NSLocalizedString(@"Check of all selected items successfully passed.",@"check of all selected items successfully passed message"); + } + + if(message) { + [[NSAlert alertWithMessageText:[NSString stringWithFormat:@"Check %@", 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 checking selected items", @"error while checking selected items message")]; + [alert setAccessoryView:statusTableAccessoryView]; + [alert beginSheetModalForWindow:tableWindow modalDelegate:self didEndSelector:@selector(sheetDidEnd:returnCode:contextInfo:) contextInfo:@"statusError"]; + } - message = [NSString stringWithFormat:@"%@\n\nMySQL said: %@", message, [result objectForKey:@"Msg_text"]]; - [[NSAlert alertWithMessageText:[NSString stringWithFormat:@"Check table '%@'", [self table]] - defaultButton:@"OK" - alternateButton:nil - otherButton:nil - informativeTextWithFormat:message] - beginSheetModalForWindow:tableWindow - modalDelegate:self - didEndSelector:NULL - contextInfo:NULL]; } /** @@ -2945,7 +2985,6 @@ // table menu items if ([menuItem action] == @selector(showCreateTableSyntax:) || [menuItem action] == @selector(copyCreateTableSyntax:) || - [menuItem action] == @selector(checkTable:) || [menuItem action] == @selector(analyzeTable:) || [menuItem action] == @selector(optimizeTable:) || [menuItem action] == @selector(repairTable:) || @@ -2955,6 +2994,10 @@ return ([self table] != nil && [[self table] isNotEqualTo:@""]); } + if ([menuItem action] == @selector(checkTable:)) { + return ([[[tablesListInstance valueForKeyPath:@"tablesListView"] selectedRowIndexes] count]) ? YES:NO; + } + if ([menuItem action] == @selector(addConnectionToFavorites:)) { return ([connectionController selectedFavorite] ? NO : YES); } @@ -3689,6 +3732,37 @@ } #pragma mark - +#pragma mark Datasource methods + +- (NSInteger)numberOfRowsInTableView:(NSTableView *)aTableView +{ + if(statusTableView && aTableView == statusTableView) + return [statusValues count]; + return 0; +} + +- (id)tableView:(NSTableView *)aTableView objectValueForTableColumn:(NSTableColumn *)aTableColumn row:(NSInteger)rowIndex +{ + if(statusTableView && aTableView == statusTableView && rowIndex < [statusValues count]) { + if ([[aTableColumn identifier] isEqualToString:@"table_name"]) { + return [[statusValues objectAtIndex:rowIndex] objectForKey:@"Table"]; + } + else if ([[aTableColumn identifier] isEqualToString:@"msg_status"]) { + return [[statusValues objectAtIndex:rowIndex] objectForKey:@"Msg_type"]; + } + else if ([[aTableColumn identifier] isEqualToString:@"msg_text"]) { + return [[statusValues objectAtIndex:rowIndex] objectForKey:@"Msg_text"]; + } + } + return nil; +} + +- (BOOL)tableView:(NSTableView *)aTableView shouldEditTableColumn:(NSTableColumn *)aTableColumn row:(NSInteger)rowIndex +{ + return NO; +} + +#pragma mark - /** * Dealloc diff --git a/Source/TablesList.h b/Source/TablesList.h index a730fcf4..aa87dbe0 100644 --- a/Source/TablesList.h +++ b/Source/TablesList.h @@ -126,6 +126,8 @@ enum sp_table_types - (void)selectTableAtIndex:(NSNumber *)row; // Getters +- (NSArray *)selectedTableNames; +- (NSArray *)selectedTableItems; - (NSString *)tableName; - (NSInteger)tableType; - (NSArray *)tables; diff --git a/Source/TablesList.m b/Source/TablesList.m index af7f6fdc..3ca55f43 100644 --- a/Source/TablesList.m +++ b/Source/TablesList.m @@ -822,6 +822,10 @@ [separatorTableMenuItem setHidden:YES]; [separatorTableContextMenuItem setHidden:YES]; + NSMenu *tableSubMenu = [[[NSApp mainMenu] itemWithTitle:@"Table"] submenu]; + [[tableSubMenu itemAtIndex:3] setTitle:NSLocalizedString(@"Check Selected Items", @"check selected items menu item")]; + + // set window title [tableWindow setTitle:[tableDocumentInstance displaySPName]]; @@ -980,6 +984,36 @@ #pragma mark - #pragma mark Getter methods + +- (NSArray *)selectedTableNames +{ + NSIndexSet *indexes = [tablesListView selectedRowIndexes]; + + NSUInteger currentIndex = [indexes firstIndex]; + NSMutableArray *selTables = [NSMutableArray array]; + + while (currentIndex != NSNotFound) { + if([[filteredTableTypes objectAtIndex:currentIndex] integerValue] == SP_TABLETYPE_TABLE) + [selTables addObject:[filteredTables objectAtIndex:currentIndex]]; + currentIndex = [indexes indexGreaterThanIndex:currentIndex]; + } + return selTables; +} + +- (NSArray *)selectedTableItems +{ + NSIndexSet *indexes = [tablesListView selectedRowIndexes]; + + NSUInteger currentIndex = [indexes firstIndex]; + NSMutableArray *selTables = [NSMutableArray array]; + + while (currentIndex != NSNotFound) { + [selTables addObject:[filteredTables objectAtIndex:currentIndex]]; + currentIndex = [indexes indexGreaterThanIndex:currentIndex]; + } + return selTables; +} + /** * Returns the currently selected table or nil if no table or mulitple tables are selected */ |