From 0559e08ff40bc2496c6af22beb4df99cf112e13b Mon Sep 17 00:00:00 2001 From: rowanbeentje Date: Sat, 27 Mar 2010 15:01:59 +0000 Subject: - When switching tables, correctly catch disconnections and suppress error dialogs and related crashes - Move connection error sheet close method to the connection delegate - Tweak the information_schema db schema building query to be much faster on busy servers by amending the VIEW part - Set the connection lock to nil after releasing, coping with connection unlocks deferred on the main thread until after dealloc --- Source/SPConnectionDelegate.m | 17 +++++++++++++---- Source/TableDocument.h | 1 - Source/TableDocument.m | 8 -------- Source/TableSource.m | 24 ++++++++++++------------ 4 files changed, 25 insertions(+), 25 deletions(-) (limited to 'Source') diff --git a/Source/SPConnectionDelegate.m b/Source/SPConnectionDelegate.m index 6e755d1a..56a254fa 100644 --- a/Source/SPConnectionDelegate.m +++ b/Source/SPConnectionDelegate.m @@ -110,21 +110,30 @@ */ - (MCPConnectionCheck)connectionLost:(id)connection { + + // Display the connection error dialog and wait for the return code [NSApp beginSheet:connectionErrorDialog modalForWindow:tableWindow modalDelegate:self didEndSelector:nil contextInfo:nil]; + NSInteger connectionErrorCode = [NSApp runModalForWindow:connectionErrorDialog]; - NSInteger connectionErrorCode = [NSApp runModalForWindow:connectionErrorDialog]; - [NSApp endSheet:connectionErrorDialog]; [connectionErrorDialog orderOut:nil]; - + // If 'disconnect' was selected, trigger a window close. if (connectionErrorCode == MCPConnectionCheckDisconnect) { [self performSelectorOnMainThread:@selector(closeDocumentWindowAndDisconnect) withObject:nil waitUntilDone:YES]; } - + return connectionErrorCode; } +/** + * Invoked when user dismisses the error sheet displayed as a result of the current connection being lost. + */ +- (IBAction)closeErrorConnectionSheet:(id)sender +{ + [NSApp stopModalWithCode:[sender tag]]; +} + /** * Close the connection - should be performed on the main thread. * First hides the window to give code a little bit of time to clean diff --git a/Source/TableDocument.h b/Source/TableDocument.h index 8919fea6..4a943302 100644 --- a/Source/TableDocument.h +++ b/Source/TableDocument.h @@ -233,7 +233,6 @@ // Other methods - (void) setQueryMode:(NSInteger)theQueryMode; - (IBAction)closeSheet:(id)sender; -- (IBAction)closeErrorConnectionSheet:(id)sender; - (IBAction)closePanelSheet:(id)sender; - (void)doPerformQueryService:(NSString *)query; - (void)doPerformLoadQueryService:(NSString *)query; diff --git a/Source/TableDocument.m b/Source/TableDocument.m index 7725ee1c..d73fa943 100644 --- a/Source/TableDocument.m +++ b/Source/TableDocument.m @@ -2247,14 +2247,6 @@ [NSApp stopModalWithCode:0]; } -/** - * Invoked when user dismisses the error sheet displayed as a result of the current connection being lost. - */ -- (IBAction)closeErrorConnectionSheet:(id)sender -{ - [NSApp stopModalWithCode:[sender tag]]; -} - /** * Closes either the server variables or create syntax sheets. */ diff --git a/Source/TableSource.m b/Source/TableSource.m index 8ccc682e..83e3dde1 100644 --- a/Source/TableSource.m +++ b/Source/TableSource.m @@ -75,15 +75,15 @@ // If an error occurred, reset the interface and abort if ([mySQLConnection queryErrored]) { - NSString *errorMessage = [NSString stringWithString:[mySQLConnection getLastErrorMessage]]; - [[NSNotificationCenter defaultCenter] postNotificationName:@"SMySQLQueryHasBeenPerformed" object:tableDocumentInstance]; [[self onMainThread] setTableDetails:nil]; - SPBeginAlertSheet(NSLocalizedString(@"Error", @"error"), NSLocalizedString(@"OK", @"OK button"), - nil, nil, [NSApp mainWindow], self, nil, nil, nil, - [NSString stringWithFormat:NSLocalizedString(@"An error occurred while retrieving information.\nMySQL said: %@", @"message of panel when retrieving information failed"), - errorMessage]); + if ([mySQLConnection isConnected]) { + SPBeginAlertSheet(NSLocalizedString(@"Error", @"error"), NSLocalizedString(@"OK", @"OK button"), + nil, nil, [NSApp mainWindow], self, nil, nil, nil, + [NSString stringWithFormat:NSLocalizedString(@"An error occurred while retrieving information.\nMySQL said: %@", @"message of panel when retrieving information failed"), + [mySQLConnection getLastErrorMessage]]); + } if (tableSourceResult) [tableSourceResult release]; return; } @@ -97,15 +97,15 @@ // If an error occurred, reset the interface and abort if ([mySQLConnection queryErrored]) { - NSString *errorMessage = [NSString stringWithString:[mySQLConnection getLastErrorMessage]]; - [[NSNotificationCenter defaultCenter] postNotificationName:@"SMySQLQueryHasBeenPerformed" object:tableDocumentInstance]; [[self onMainThread] setTableDetails:nil]; - SPBeginAlertSheet(NSLocalizedString(@"Error", @"error"), NSLocalizedString(@"OK", @"OK button"), - nil, nil, [NSApp mainWindow], self, nil, nil, nil, - [NSString stringWithFormat:NSLocalizedString(@"An error occurred while retrieving information.\nMySQL said: %@", @"message of panel when retrieving information failed"), - errorMessage]); + if ([mySQLConnection isConnected]) { + SPBeginAlertSheet(NSLocalizedString(@"Error", @"error"), NSLocalizedString(@"OK", @"OK button"), + nil, nil, [NSApp mainWindow], self, nil, nil, nil, + [NSString stringWithFormat:NSLocalizedString(@"An error occurred while retrieving information.\nMySQL said: %@", @"message of panel when retrieving information failed"), + [mySQLConnection getLastErrorMessage]]); + } if (indexResult) [indexResult release]; return; } -- cgit v1.2.3