aboutsummaryrefslogtreecommitdiffstats
path: root/Source/CMMCPConnection.m
diff options
context:
space:
mode:
authorrowanbeentje <rowan@beent.je>2009-07-09 00:10:58 +0000
committerrowanbeentje <rowan@beent.je>2009-07-09 00:10:58 +0000
commit3c85831742d01fd4dbf35b819038900018bb3a5d (patch)
treea5cbedc67d43161cb0e7e314d163abd527e89382 /Source/CMMCPConnection.m
parent9818e55d8d240314fa05f76ba8b7c9ed5ba43d00 (diff)
downloadsequelpro-3c85831742d01fd4dbf35b819038900018bb3a5d.tar.gz
sequelpro-3c85831742d01fd4dbf35b819038900018bb3a5d.tar.bz2
sequelpro-3c85831742d01fd4dbf35b819038900018bb3a5d.zip
- Fix connection controller errors with nil strings (bindings?), fixing Issue #331
- Make the "optional" socket more optional: add a list of common socket file locations that are checked (instead of just /tmp/mysql.sock), including MAMP to address a common use case
Diffstat (limited to 'Source/CMMCPConnection.m')
-rw-r--r--Source/CMMCPConnection.m37
1 files changed, 37 insertions, 0 deletions
diff --git a/Source/CMMCPConnection.m b/Source/CMMCPConnection.m
index df71ff82..0e3e085a 100644
--- a/Source/CMMCPConnection.m
+++ b/Source/CMMCPConnection.m
@@ -81,6 +81,9 @@ static void forcePingTimeout(int signalNumber);
mConnectionFlags = kMCPConnectionDefaultOption;
+ if (!host) host = @"";
+ if (!login) login = @"";
+
connectionHost = [[NSString alloc] initWithString:host];
connectionLogin = [[NSString alloc] initWithString:login];
connectionPort = port;
@@ -101,6 +104,12 @@ static void forcePingTimeout(int signalNumber);
}
mConnectionFlags = kMCPConnectionDefaultOption;
+
+ if (!socket || ![socket length]) {
+ socket = [self findSocketPath];
+ if (!socket) socket = @"";
+ }
+ if (!login) login = @"";
connectionHost = nil;
connectionLogin = [[NSString alloc] initWithString:login];
@@ -162,6 +171,8 @@ static void forcePingTimeout(int signalNumber);
if (connectionKeychainName) [connectionKeychainName release], connectionKeychainName = nil;
if (connectionKeychainAccount) [connectionKeychainAccount release], connectionKeychainAccount = nil;
+ if (!thePassword) thePassword = @"";
+
connectionPassword = [[NSString alloc] initWithString:thePassword];
return YES;
@@ -1307,6 +1318,32 @@ static void forcePingTimeout(int signalNumber)
return(!mysql_query(mConnection, "SET GLOBAL max_allowed_packet = @@global.max_allowed_packet"));
}
+/*
+ * Check some common locations for the presence of a MySQL socket file, returning
+ * it if successful.
+ */
+- (NSString *)findSocketPath
+{
+ NSFileManager *fileManager = [NSFileManager defaultManager];
+ NSArray *possibleSocketLocations = [NSArray arrayWithObjects:
+ @"/tmp/mysql.sock", // Default
+ @"/var/run/mysqld/mysqld.sock", // As used on Debian/Gentoo
+ @"/var/tmp/mysql.sock", // As used on FreeBSD
+ @"/var/lib/mysql/mysql.sock", // As used by Fedora
+ @"/opt/local/lib/mysql/mysql.sock", // Alternate fedora
+ @"/opt/local/var/run/mysqld/mysqld.sock", // Darwinports MySQL
+ @"/opt/local/var/run/mysql4/mysqld.sock", // Darwinports MySQL 4
+ @"/opt/local/var/run/mysql5/mysqld.sock", // Darwinports MySQL 5
+ @"/Applications/MAMP/tmp/mysql/mysql.sock", // MAMP default location
+ nil];
+
+ for (int i = 0; i < [possibleSocketLocations count]; i++) {
+ if ([fileManager fileExistsAtPath:[possibleSocketLocations objectAtIndex:i]])
+ return [possibleSocketLocations objectAtIndex:i];
+ }
+
+ return nil;
+}
- (void) dealloc
{