aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Source/CustomQuery.m4
-rw-r--r--Source/SPConnectionController.h2
-rw-r--r--Source/SPConnectionController.m16
-rw-r--r--Source/SPNavigatorController.m6
-rw-r--r--Source/TableDocument.m1
5 files changed, 27 insertions, 2 deletions
diff --git a/Source/CustomQuery.m b/Source/CustomQuery.m
index 35338463..d0553f27 100644
--- a/Source/CustomQuery.m
+++ b/Source/CustomQuery.m
@@ -2806,6 +2806,10 @@
*/
- (void)historyItemsHaveBeenUpdated:(id)manager
{
+
+ // Abort if the connection has been closed already - sign of a closed window
+ if (![mySQLConnection isConnected]) return;
+
// Refresh history popup menu
NSMenu* historyMenu = [queryHistoryButton menu];
while([queryHistoryButton numberOfItems] > 7)
diff --git a/Source/SPConnectionController.h b/Source/SPConnectionController.h
index f2c6ba9a..b1cc541e 100644
--- a/Source/SPConnectionController.h
+++ b/Source/SPConnectionController.h
@@ -58,6 +58,7 @@
SPSSHTunnel *sshTunnel;
MCPConnection *mySQLConnection;
BOOL automaticFavoriteSelection;
+ BOOL cancellingConnection;
NSInteger previousType;
NSInteger type;
@@ -131,6 +132,7 @@
- (void)initiateSSHTunnelConnection;
- (void)sshTunnelCallback:(SPSSHTunnel *)theTunnel;
- (void)initiateMySQLConnection;
+- (void)cancelConnection;
- (void)failConnectionWithTitle:(NSString *)theTitle errorMessage:(NSString *)theErrorMessage detail:(NSString *)errorDetail;
- (void)errorSheetDidEnd:(NSWindow *)sheet returnCode:(NSInteger)returnCode contextInfo:(NSString *)contextInfo;
- (void)addConnectionToDocument;
diff --git a/Source/SPConnectionController.m b/Source/SPConnectionController.m
index 2e48106c..869bd35c 100644
--- a/Source/SPConnectionController.m
+++ b/Source/SPConnectionController.m
@@ -68,6 +68,7 @@
connectionSSHKeychainItemAccount = nil;
mySQLConnection = nil;
sshTunnel = nil;
+ cancellingConnection = NO;
// Load the connection nib
[NSBundle loadNibNamed:@"ConnectionView" owner:self];
@@ -165,6 +166,7 @@
if (![self checkHost]) return;
// Basic details have validated - start the connection process animating
+ cancellingConnection = NO;
[addToFavoritesButton setHidden:YES];
[addToFavoritesButton display];
[helpButton setHidden:YES];
@@ -251,12 +253,26 @@
}
/*
+ * Cancel connection.
+ * Currently only cleans up the SSH connection (MySQL connection isn't threaded)
+ */
+- (void)cancelConnection
+{
+ if (!sshTunnel) return;
+ cancellingConnection = YES;
+ [sshTunnel disconnect];
+ [sshTunnel release];
+ sshTunnel = nil;
+}
+
+/*
* A callback function for the SSH Tunnel setup process - will be called on a connection
* state change, allowing connection to fail or proceed as appropriate. If successful,
* will call initiateMySQLConnection.
*/
- (void)sshTunnelCallback:(SPSSHTunnel *)theTunnel
{
+ if (cancellingConnection) return;
NSInteger newState = [theTunnel state];
if (newState == PROXY_STATE_IDLE) {
diff --git a/Source/SPNavigatorController.m b/Source/SPNavigatorController.m
index ec3458ad..107019af 100644
--- a/Source/SPNavigatorController.m
+++ b/Source/SPNavigatorController.m
@@ -90,8 +90,10 @@ static SPNavigatorController *sharedNavigatorController = nil;
if ([[[NSDocumentController sharedDocumentController] documents] count]) {
for(id doc in [[NSDocumentController sharedDocumentController] documents]) {
NSString *connectionName = [NSString stringWithFormat:@"%@@%@", [doc user], [doc host]];
- if(![schemaData objectForKey:connectionName])
- [schemaData setObject:[[doc valueForKeyPath:@"mySQLConnection"] getDbStructure] forKey:connectionName];
+ if(![schemaData objectForKey:connectionName]) {
+ NSDictionary *dbStructure = [[doc valueForKeyPath:@"mySQLConnection"] getDbStructure];
+ if (dbStructure) [schemaData setObject:dbStructure forKey:connectionName];
+ }
}
}
diff --git a/Source/TableDocument.m b/Source/TableDocument.m
index a262f09d..3a7fd59b 100644
--- a/Source/TableDocument.m
+++ b/Source/TableDocument.m
@@ -3591,6 +3591,7 @@
{
[mySQLConnection setDelegate:nil];
if (_isConnected) [self closeConnection];
+ else [connectionController cancelConnection];
if ([[[SPQueryController sharedQueryController] window] isVisible]) [self toggleConsole:self];
if ([[[SPNavigatorController sharedNavigatorController] window] isVisible]) [self toggleNavigator:self];
[createTableSyntaxWindow orderOut:nil];