diff options
author | rowanbeentje <rowan@beent.je> | 2009-08-07 23:57:16 +0000 |
---|---|---|
committer | rowanbeentje <rowan@beent.je> | 2009-08-07 23:57:16 +0000 |
commit | 2297b13252ee7149606ecd4544898614f0ac9298 (patch) | |
tree | e9d704588859ba7b18a783f5ae214052d68fa8bf /Source/SPConnectionController.m | |
parent | 67a72bc3a598528f9d45010716df3554dd882241 (diff) | |
download | sequelpro-2297b13252ee7149606ecd4544898614f0ac9298.tar.gz sequelpro-2297b13252ee7149606ecd4544898614f0ac9298.tar.bz2 sequelpro-2297b13252ee7149606ecd4544898614f0ac9298.zip |
Merge in recent fixes from trunk for 0.9.6 release:
- r1145 (Custom Query completion fixes)
- r1148 (CSV file import reload bugfix)
- Parts of r1150 (history navigation no longer generates invalid states)
- r1172 (Add to favorites and favorites saving fixes)
Diffstat (limited to 'Source/SPConnectionController.m')
-rw-r--r-- | Source/SPConnectionController.m | 37 |
1 files changed, 18 insertions, 19 deletions
diff --git a/Source/SPConnectionController.m b/Source/SPConnectionController.m index e5a0a473..b27f24f2 100644 --- a/Source/SPConnectionController.m +++ b/Source/SPConnectionController.m @@ -657,8 +657,8 @@ { NSString *thePassword, *theSSHPassword; NSNumber *favoriteid = [NSNumber numberWithInt:[[NSString stringWithFormat:@"%f", [[NSDate date] timeIntervalSince1970]] hash]]; - NSString *favoriteName = [[self name] length]?[self name]:[NSString stringWithFormat:@"%@@%@", [self user], [self host]]; - if (![[self name] length] && ![[self database] isEqualToString:@""]) + NSString *favoriteName = [[self name] length]?[self name]:[NSString stringWithFormat:@"%@@%@", ([self user] && [[self user] length])?[self user]:@"anonymous", [self host]]; + if (![[self name] length] && [self database] && ![[self database] isEqualToString:@""]) favoriteName = [NSString stringWithFormat:@"%@ %@", [self database], favoriteName]; // Ensure that host is not empty if this is a TCP/IP or SSH connection @@ -676,21 +676,20 @@ // Ensure that a socket connection is not inadvertently used if (![self checkHost]) return; - // Construct the favorite details - NSDictionary *newFavorite = [NSDictionary dictionaryWithObjectsAndKeys: - [NSNumber numberWithInt:[self type]], @"type", - favoriteName, @"name", - [self host], @"host", - [self socket], @"socket", - [self user], @"user", - [self port], @"port", - [self database], @"database", - [self sshHost], @"sshHost", - [self sshUser], @"sshUser", - [self sshPort], @"sshPort", - favoriteid, @"id", - nil]; - + // Construct the favorite details - cannot use only dictionaryWithObjectsAndKeys for possible nil values. + NSMutableDictionary *newFavorite = [NSMutableDictionary dictionaryWithObjectsAndKeys: + [NSNumber numberWithInt:[self type]], @"type", + favoriteName, @"name", + [self host], @"host", + favoriteid, @"id", + nil]; + if ([self socket]) [newFavorite setObject:[self socket] forKey:@"socket"]; + if ([self user]) [newFavorite setObject:[self user] forKey:@"user"]; + if ([self port]) [newFavorite setObject:[self port] forKey:@"port"]; + if ([self database]) [newFavorite setObject:[self database] forKey:@"database"]; + if ([self sshHost]) [newFavorite setObject:[self sshHost] forKey:@"sshHost"]; + if ([self sshUser]) [newFavorite setObject:[self sshUser] forKey:@"sshUser"]; + if ([self sshPort]) [newFavorite setObject:[self sshPort] forKey:@"sshPort"]; // Add the new favorite to the user defaults array NSMutableArray *currentFavorites; @@ -708,7 +707,7 @@ if (mySQLConnection && connectionKeychainItemName) { thePassword = [keychain getPasswordForName:connectionKeychainItemName account:connectionKeychainItemAccount]; } - if (![thePassword isEqualToString:@""]) { + if (thePassword && ![thePassword isEqualToString:@""]) { [keychain addPassword:thePassword forName:[keychain nameForFavoriteName:favoriteName id:[NSString stringWithFormat:@"%i", [favoriteid intValue]]] account:[keychain accountForUser:[self user] host:[self host] database:[self database]]]; @@ -719,7 +718,7 @@ if (mySQLConnection && connectionSSHKeychainItemName) { theSSHPassword = [keychain getPasswordForName:connectionSSHKeychainItemName account:connectionSSHKeychainItemAccount]; } - if (![theSSHPassword isEqualToString:@""]) { + if (theSSHPassword && ![theSSHPassword isEqualToString:@""]) { [keychain addPassword:theSSHPassword forName:[keychain nameForSSHForFavoriteName:favoriteName id:[NSString stringWithFormat:@"%i", [favoriteid intValue]]] account:[keychain accountForSSHUser:[self sshUser] sshHost:[self sshHost]]]; |