use the actual unique id to compare connection (#17229)

* use the actual unique id to compare connection

* fix test error and pr comments
This commit is contained in:
Alan Ren
2021-10-04 15:24:09 -07:00
committed by GitHub
parent 32b912c37e
commit c20ed1bd9b
2 changed files with 3 additions and 19 deletions

View File

@@ -7,7 +7,6 @@ import { ConnectionProfileGroup } from 'sql/platform/connection/common/connectio
import * as azdata from 'azdata';
import { ProviderConnectionInfo } from 'sql/platform/connection/common/providerConnectionInfo';
import * as interfaces from 'sql/platform/connection/common/interfaces';
import { equalsIgnoreCase } from 'vs/base/common/strings';
import { generateUuid } from 'vs/base/common/uuid';
import { ICapabilitiesService } from 'sql/platform/capabilities/common/capabilitiesService';
import { isString } from 'vs/base/common/types';
@@ -83,15 +82,8 @@ export class ConnectionProfile extends ProviderConnectionInfo implements interfa
this.options['databaseDisplayName'] = this.databaseName;
}
public static matchesProfile(a: interfaces.IConnectionProfile, b: interfaces.IConnectionProfile): boolean {
return a && b
&& a.providerName === b.providerName
&& ConnectionProfile.nullCheckEqualsIgnoreCase(a.serverName, b.serverName)
&& ConnectionProfile.nullCheckEqualsIgnoreCase(a.databaseName, b.databaseName)
&& ConnectionProfile.nullCheckEqualsIgnoreCase(a.userName, b.userName)
&& ConnectionProfile.nullCheckEqualsIgnoreCase(a.options['databaseDisplayName'], b.options['databaseDisplayName'])
&& a.authenticationType === b.authenticationType
&& a.groupId === b.groupId;
public static matchesProfile(a: interfaces.IConnectionProfile | undefined, b: interfaces.IConnectionProfile | undefined): boolean {
return a && b && a.getOptionsKey() === b.getOptionsKey();
}
public matches(other: interfaces.IConnectionProfile): boolean {
@@ -99,15 +91,6 @@ export class ConnectionProfile extends ProviderConnectionInfo implements interfa
}
private static nullCheckEqualsIgnoreCase(a?: string, b?: string) {
if (a && !b || b && !a) {
return false;
} else {
let bothNull: boolean = !a && !b;
return bothNull ? bothNull : equalsIgnoreCase(a!, b!);
}
}
public generateNewId() {
this._id = generateUuid();
}

View File

@@ -251,6 +251,7 @@ suite('SQL ConnectionStatusManager tests', () => {
newConnection.options['databaseDisplayName'] = newConnection.databaseName;
connections.addConnection(newConnection, 'test_uri_1');
connections.addConnection(newConnection, 'test_uri_2');
newConnection = new ConnectionProfile(capabilitiesService, newConnection);
// Get the connections and verify that the duplicate is only returned once
let activeConnections = connections.getActiveConnectionProfiles();