Set original database for connection done through connection dialog (#17266)

* check if database connection

* Change name of isMaster and remove import

* Set to false

* take out connecttodatabase

* remove connecttodatabase

* Original database

* remove empty string check

* clean

* set original database for when saving connection

* pass unit test

* map -> find

* PR changes

* Comments for original database
This commit is contained in:
nasc17
2021-10-08 13:10:28 -07:00
committed by GitHub
parent a25dd2c03b
commit 75d6847a65
6 changed files with 37 additions and 28 deletions

View File

@@ -70,6 +70,9 @@ export class ConnectionProfile extends ProviderConnectionInfo implements interfa
this.options.expiresOn = model.options.expiresOn;
}
}
if (model.options?.originalDatabase) {
this.originalDatabase = model.options.originalDatabase;
}
} else {
//Default for a new connection
this.savePassword = false;
@@ -142,6 +145,19 @@ export class ConnectionProfile extends ProviderConnectionInfo implements interfa
this.options['azureResourceId'] = value;
}
/**
* Database of server specified before connection.
* Some providers will modify the database field of the connection once a connection is made
* so that it reflects the actual database that was connected to.
*/
public get originalDatabase() {
return this.options['originalDatabase'];
}
public set originalDatabase(value: string | undefined) {
this.options['originalDatabase'] = value;
}
public get registeredServerDescription(): string {
return this.options['registeredServerDescription'];
}

View File

@@ -6,7 +6,6 @@
import { IConnectionProfile } from 'sql/platform/connection/common/interfaces';
import { ConnectionProfile } from 'sql/platform/connection/common/connectionProfile';
import { ConnectionProfileGroup } from 'sql/platform/connection/common/connectionProfileGroup';
import { mssqlProviderName } from 'sql/platform/connection/common/constants';
// CONSTANTS //////////////////////////////////////////////////////////////////////////////////////
const msInH = 3.6e6;
@@ -134,9 +133,7 @@ export function findProfileInGroup(og: IConnectionProfile, groups: ConnectionPro
return undefined;
}
export function isMaster(profile: IConnectionProfile): boolean {
// TODO: the connection profile should have a property to indicate whether the connection is a server connection or database connection
// created issue to track the problem: https://github.com/Microsoft/azuredatastudio/issues/5193.
return (profile.providerName === mssqlProviderName && profile.databaseName?.toLowerCase() === 'master')
|| (profile.providerName.toLowerCase() === 'pgsql' && profile.databaseName?.toLowerCase() === 'postgres');
export function isServerConnection(profile: IConnectionProfile): boolean {
// If the user did not specify a database in the original connection, then this is considered a server-level connection
return !profile.options.originalDatabase;
}