Commits

Tuukka Norri committed fd1f297

Fixed bugs with database URI handling

  • Participants
  • Parent commits 8de2af6

Comments (0)

Files changed (2)

BaseTenAppKit/Sources/BXNetServiceConnector.m

 	else
 		mConnectorImpl = [[BXApplicationModalNSConnectorImplementation alloc] initWithConnector: self];
 	
+	if (! [mContext databaseURI])
+		[mContext setDatabaseURI: [NSURL URLWithString: @"pgsql:///"]];
+	
 	[mConnectorImpl beginConnectionAttempt];
 	
 	//If we have a host, try to reach it. Otherwise, display the panel.
 		
 		//Complete the database URI. If we're allowed to use the Keychain, try to fetch some credentials.
 		//If none are found, display the authentication panel. Otherwise connect.
+		//Don't use -setDatabaseURIInternal: because we just got a new host name.
 		NSURL* databaseURI = [mContext databaseURI];
 		databaseURI = [databaseURI BXURIForHost: mHostName
 										   port: (-1 == mPort ? nil : [NSNumber numberWithInteger: mPort])
 									   database: nil 
 									   username: nil 
 									   password: nil];
-		[mContext setDatabaseURIInternal: databaseURI];
+		[mContext setDatabaseURI: databaseURI];
 				
 		if ([mContext usesKeychain])
             [mContext fetchPasswordFromKeychain];

Sources/BXDatabaseContext.m

 - (void) setDatabaseURI: (NSURL *) uri
 {
 	[self setKeychainPasswordItem: NULL];
-	[self setDatabaseObjectModel: nil];
-
 	if (! [[uri scheme] isEqual: [mDatabaseURI scheme]])
 	{
 		[self setDatabaseInterface: nil];
 		[self databaseInterface];
 	}
 
+	if (mDatabaseURI && 0 < [[mDatabaseURI host] length])
+		[self setDatabaseObjectModel: nil];
+	
 	[self setDatabaseURIInternal: uri];
 
-	if (0 < [[uri host] length])
+	if (0 < [[mDatabaseURI host] length])
 	{
 		[self databaseObjectModel];
 
 		[self setDatabaseURIInternal: newURI];
 				
 		NSNotification* notification = nil;
-		if ([mObjectModel contextConnectedUsingDatabaseInterface: mDatabaseInterface error: &localError])
+		if ([[self databaseObjectModel] contextConnectedUsingDatabaseInterface: mDatabaseInterface error: &localError])
 		{
 			[mObjectModel setCanCreateEntityDescriptions: NO];
 			notification = [NSNotification notificationWithName: kBXConnectionSuccessfulNotification object: self userInfo: nil];
 		else
 		{
 			retval = NO;
-			if (NULL != error)
-				*error = localError;
+			NSDictionary* userInfo = nil;
 			[mDatabaseInterface disconnect];
-			NSDictionary* userInfo = [NSDictionary dictionaryWithObject: localError forKey: kBXErrorKey];
+
+			if (localError)
+			{
+				userInfo = [NSDictionary dictionaryWithObject: localError forKey: kBXErrorKey];
+				if (NULL != error)
+					*error = localError;
+			}
 			notification = [NSNotification notificationWithName: kBXConnectionFailedNotification object: self userInfo: userInfo];
 			[mDelegateProxy databaseContext: self failedToConnect: localError];
 		}