mirror of
https://github.com/ckaczor/azuredatastudio.git
synced 2026-01-22 01:25:38 -05:00
allow database name to be empty (#20221)
* allow database to be empty * test changes * fix import * fix test cases * comment
This commit is contained in:
@@ -32,7 +32,7 @@ import { Task } from 'sql/workbench/services/tasks/browser/tasksRegistry';
|
||||
import { IObjectExplorerService } from 'sql/workbench/services/objectExplorer/browser/objectExplorerService';
|
||||
import { IEditorService } from 'vs/workbench/services/editor/common/editorService';
|
||||
import { IQueryEditorService } from 'sql/workbench/services/queryEditor/common/queryEditorService';
|
||||
import { IConnectionProfile } from 'sql/platform/connection/common/interfaces';
|
||||
import { ConnectionOptionSpecialType, IConnectionProfile } from 'sql/platform/connection/common/interfaces';
|
||||
import { getCurrentGlobalConnection } from 'sql/workbench/browser/taskUtilities';
|
||||
import { ServicesAccessor, IInstantiationService } from 'vs/platform/instantiation/common/instantiation';
|
||||
import { CommandsRegistry, ICommandService } from 'vs/platform/commands/common/commands';
|
||||
@@ -655,7 +655,8 @@ export class ListDatabasesActionItem extends Disposable implements IActionViewIt
|
||||
@IContextViewService contextViewProvider: IContextViewService,
|
||||
@IConnectionManagementService private readonly connectionManagementService: IConnectionManagementService,
|
||||
@INotificationService private readonly notificationService: INotificationService,
|
||||
@ILogService private readonly logService: ILogService
|
||||
@ILogService private readonly logService: ILogService,
|
||||
@ICapabilitiesService private readonly capabilitiesService: ICapabilitiesService
|
||||
) {
|
||||
super();
|
||||
this._databaseListDropdown = $('.databaseListDropdown');
|
||||
@@ -751,6 +752,8 @@ export class ListDatabasesActionItem extends Disposable implements IActionViewIt
|
||||
severity: Severity.Error,
|
||||
message: nls.localize('changeDatabase.failed', "Failed to change database")
|
||||
});
|
||||
} else {
|
||||
this._dropdown.options.strictSelection = true;
|
||||
}
|
||||
},
|
||||
error => {
|
||||
@@ -860,9 +863,16 @@ export class ListDatabasesActionItem extends Disposable implements IActionViewIt
|
||||
}
|
||||
|
||||
private updateConnection(databaseName: string): void {
|
||||
// Ignore if the database name is not provided, this happens when the query editor connection is changed to
|
||||
// a provider that does not support database.
|
||||
if (!databaseName) {
|
||||
if (!this._editor?.input) {
|
||||
return;
|
||||
}
|
||||
const profile = this.connectionManagementService.getConnectionProfile(this._editor.input.uri);
|
||||
if (!profile) {
|
||||
return;
|
||||
}
|
||||
const supportDatabase = !!(this.capabilitiesService.getCapabilities(profile.providerName).connection.connectionOptions?.find(option => option.specialValueType === ConnectionOptionSpecialType.databaseName));
|
||||
// Ignore if the provider does not support database.
|
||||
if (!supportDatabase) {
|
||||
return;
|
||||
}
|
||||
this._isConnected = true;
|
||||
@@ -873,6 +883,12 @@ export class ListDatabasesActionItem extends Disposable implements IActionViewIt
|
||||
this._dropdown.value = databaseName;
|
||||
this._dropdown.values = [databaseName];
|
||||
this._dropdown.enabled = true;
|
||||
|
||||
// Set the strict selection to false so that it is allowed to not to have a database selected to begin with.
|
||||
// e.g. MySQL allows server level query.
|
||||
if (!databaseName) {
|
||||
this._dropdown.options.strictSelection = false;
|
||||
}
|
||||
this.getDatabaseNames().then(databaseNames => {
|
||||
this._dropdown.values = databaseNames;
|
||||
}).catch(onUnexpectedError);
|
||||
|
||||
Reference in New Issue
Block a user