Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
try {
var connectId;
if (context) {
let connection = context.connectionProfile;
connectId = connection.id;
} else {
let connection = await sqlops.connection.getCurrentConnection();
connectId = connection.connectionId;
}
let doc = await vscode.workspace.openTextDocument(setting);
let editor = await vscode.window.showTextDocument(doc, 1, false);
editor.edit(edit => {
edit.insert(new vscode.Position(0, 0), scriptText);
});
if (connectId) {
await sqlops.queryeditor.connect(doc.uri.toString(), connectId);
}
} catch (err) {
vscode.window.showErrorMessage(err);
}
}
}
editor.selection = newSelection;
}
if ((context || connection) && this.connectionId) {
if (this.dbName !== '') {
var providerName:string;
if (context) {
providerName = context.connectionProfile.providerName;
} else if (connection) {
providerName = connection.providerId;
}
let dProvider = await sqlops.dataprotocol.getProvider(providerName, sqlops.DataProviderType.ConnectionProvider);
let connectionUri = await sqlops.connection.getUriForConnection(this.connectionId);
await dProvider.changeDatabase(connectionUri,this.dbName);
}
await sqlops.queryeditor.connect(doc.uri.toString(), this.connectionId);
}
} catch (err) {
vscode.window.showErrorMessage(err);
}
}
export async function utilizeConnection(doc: vscode.TextDocument, actualConnectionInfo: actualConnectionInfo) {
if ( actualConnectionInfo.connectHoldId ) {
if (actualConnectionInfo.dbName !== '') {
let dProvider = await azdata.dataprotocol.getProvider(actualConnectionInfo.providerId, azdata.DataProviderType.ConnectionProvider);
let connectionUri = await azdata.connection.getUriForConnection(actualConnectionInfo.connectHoldId);
await dProvider.changeDatabase(connectionUri,actualConnectionInfo.dbName);
await azdata.queryeditor.connect(doc.uri.toString(), actualConnectionInfo.connectHoldId);
}
}
}
export async function changeDatabase(databaseList, connection) {
let connectionUri = await azdata.connection.getUriForConnection(connection.connectionId);
let dProvider = await azdata.dataprotocol.getProvider(connection.providerId, azdata.DataProviderType.ConnectionProvider);
if (dProvider.providerId == "MSSQL") {
let selectedDatabase = await vscode.window.showQuickPick(databaseList,
{ placeHolder: 'Select Database', "ignoreFocusOut": true}
);
let useThisDB = selectedDatabase;
await dProvider.changeDatabase(connectionUri,useThisDB);
await azdata.queryeditor.connect(vscode.window.activeTextEditor.document.uri.toString(), connection.connectionId);
} else {
vscode.window.showErrorMessage("Sorry, use database is only supported for MS SQL");
}
};