Fix for database name in connection details after changing database (#22376)

This commit is contained in:
Alex Ma
2023-05-18 14:34:54 -07:00
committed by GitHub
parent 7d0a7a6721
commit 89386c9c11
14 changed files with 76 additions and 36 deletions

View File

@@ -990,7 +990,7 @@ suite('SQL ConnectionManagementService tests', () => {
test('Edit Connection - Changing connection profile name for same URI should persist after edit', async () => {
let profile = Object.assign({}, connectionProfile);
let uri1 = 'test_uri1';
let uri1 = 'connection:test_uri1';
let newname = 'connection renamed';
let options: IConnectionCompletionOptions = {
params: {
@@ -1017,18 +1017,19 @@ suite('SQL ConnectionManagementService tests', () => {
//In a real scenario this would be false as it would match the first instance and not find a duplicate.
return Promise.resolve(false);
});
profile.getOptionsKey = () => { return 'test_uri1'; };
await connect(uri1, options, true, profile);
let newProfile = Object.assign({}, connectionProfile);
newProfile.connectionName = newname;
newProfile.getOptionsKey = () => { return 'test_uri1'; };
options.params.isEditConnection = true;
await connect(uri1, options, true, newProfile);
assert.strictEqual(connectionManagementService.getConnectionProfile(uri1).connectionName, newname);
});
test('Edit Connection - Connecting a different URI with same profile via edit should not change profile ID.', async () => {
let uri1 = 'test_uri1';
let uri2 = 'test_uri2';
test('Edit Connection - Connecting a different non editor URI with same profile via edit should not change profile ID.', async () => {
let currentUri = 'test_uri1';
let uri = 'connection:' + currentUri;
let profile = Object.assign({}, connectionProfile);
profile.id = '0451';
let options: IConnectionCompletionOptions = {
@@ -1040,7 +1041,7 @@ suite('SQL ConnectionManagementService tests', () => {
onConnectStart: undefined,
onDisconnect: undefined,
onConnectCanceled: undefined,
uri: uri1
uri: uri
},
queryRange: undefined,
runQueryOnCompletion: RunQueryOnConnectionMode.none,
@@ -1052,14 +1053,17 @@ suite('SQL ConnectionManagementService tests', () => {
showFirewallRuleOnError: true
};
// In an actual edit situation, the profile options would be different for different URIs, as a placeholder, we check the test uris instead here.
connectionStore.setup(x => x.isDuplicateEdit(TypeMoq.It.isAny(), TypeMoq.It.isAny())).returns(() => Promise.resolve(uri1 === uri2));
// In an actual edit situation, the profile options would be different for different URIs, as a placeholder, we return false.
connectionStore.setup(x => x.isDuplicateEdit(TypeMoq.It.isAny(), TypeMoq.It.isAny())).returns(() => Promise.resolve(false));
profile.getOptionsKey = () => { return currentUri; };
await connect(uri1, options, true, profile);
await connect(uri, options, true, profile);
let uri1info = connectionManagementService.getConnectionInfo(uri);
options.params.isEditConnection = true;
await connect(uri2, options, true, profile);
let uri1info = connectionManagementService.getConnectionInfo(uri1);
let uri2info = connectionManagementService.getConnectionInfo(uri2);
currentUri = 'test_uri2';
uri = 'connection:' + currentUri;
await connect(uri, options, true, profile);
let uri2info = connectionManagementService.getConnectionInfo(uri);
assert.strictEqual(uri1info.connectionProfile.id, uri2info.connectionProfile.id);
});

View File

@@ -51,7 +51,7 @@ export class QueryEditorService implements IQueryEditorService {
/**
* Creates new untitled document for SQL/Kusto query and opens in new editor tab
*/
public async newSqlEditor(options: INewSqlEditorOptions = {}, connectionProviderName?: string): Promise<UntitledQueryEditorInput> {
public async newSqlEditor(options: INewSqlEditorOptions = {}, connectionProviderName?: string, initialConnectionUri?: string): Promise<UntitledQueryEditorInput> {
options = mixin(options, defaults, false);
// Create file path and file URI
let docUri: URI = options.resource ?? URI.from({ scheme: Schemas.untitled, path: await this.createUntitledSqlFilePath(connectionProviderName) });
@@ -68,7 +68,7 @@ export class QueryEditorService implements IQueryEditorService {
}
const queryResultsInput: QueryResultsInput = this._instantiationService.createInstance(QueryResultsInput, docUri.toString());
let queryInput = this._instantiationService.createInstance(UntitledQueryEditorInput, options.description, fileInput, queryResultsInput);
let queryInput = this._instantiationService.createInstance(UntitledQueryEditorInput, options.description, fileInput, queryResultsInput, initialConnectionUri);
let profile: IConnectionProfile | undefined = undefined;
// If we're told to connect then get the connection before opening the editor since it will try to get the connection for the current
// active editor and so we need to get this before opening a new one.
@@ -94,7 +94,7 @@ export class QueryEditorService implements IQueryEditorService {
/**
* Creates new edit data session
*/
public async newEditDataEditor(schemaName: string, tableName: string, sqlContent: string): Promise<IConnectableInput> {
public async newEditDataEditor(schemaName: string, tableName: string, sqlContent: string, initialConnectionUri?: string): Promise<IConnectableInput> {
// Create file path and file URI
let objectName = schemaName ? schemaName + '.' + tableName : tableName;
@@ -108,7 +108,7 @@ export class QueryEditorService implements IQueryEditorService {
(m as UntitledTextEditorModel).setDirty(false);
// Create an EditDataInput for editing
const resultsInput: EditDataResultsInput = this._instantiationService.createInstance(EditDataResultsInput, docUri.toString());
let editDataInput: EditDataInput = this._instantiationService.createInstance(EditDataInput, docUri, schemaName, tableName, fileInput, sqlContent, resultsInput);
let editDataInput: EditDataInput = this._instantiationService.createInstance(EditDataInput, docUri, schemaName, tableName, fileInput, sqlContent, resultsInput, initialConnectionUri);
// Determine whether to show edit data upon opening.
editDataInput.queryPaneEnabled = this._configurationService.getValue('editor.showEditDataSqlPaneOnStartup');
if (sqlContent) {

View File

@@ -45,8 +45,8 @@ export interface IQueryEditorService {
_serviceBrand: undefined;
// Creates new untitled document for SQL/KUSTO queries and opens it in a new editor tab
newSqlEditor(options?: INewSqlEditorOptions, connectionProviderName?: string): Promise<IUntitledQueryEditorInput>;
newSqlEditor(options?: INewSqlEditorOptions, connectionProviderName?: string, initialConnectionUri?: string): Promise<IUntitledQueryEditorInput>;
// Creates new edit data session
newEditDataEditor(schemaName: string, tableName: string, queryString: string): Promise<IConnectableInput>;
newEditDataEditor(schemaName: string, tableName: string, queryString: string, initialConnectionUri?: string): Promise<IConnectableInput>;
}

View File

@@ -22,7 +22,7 @@ export class TestQueryEditorService implements IQueryEditorService {
async newSqlEditor(options?: INewSqlEditorOptions): Promise<IUntitledQueryEditorInput> {
const base = await this.editorService.createEditorInput({ resource: undefined, forceUntitled: true }) as UntitledTextEditorInput;
return Promise.resolve(this.instantiationService.createInstance(UntitledQueryEditorInput, '', base, new QueryResultsInput(base.resource.toString(true))));
return Promise.resolve(this.instantiationService.createInstance(UntitledQueryEditorInput, '', base, new QueryResultsInput(base.resource.toString(true)), undefined));
}
newEditDataEditor(schemaName: string, tableName: string, queryString: string): Promise<IConnectableInput> {