Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
azdata.connection.getCurrentConnection().then( connection => {
if (connection) {
let databaseList = azdata.connection.listDatabases(connection.connectionId);
changeDatabase(databaseList, connection);
} else {
vscode.window.showErrorMessage("No connection found. Connect before switching databases.");
}
}, error => {
console.info(error);
public async placescript(fileName, scriptText, context?: sqlops.ObjectExplorerContext) {
var setting: vscode.Uri = vscode.Uri.parse("untitled:" + fileName);
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);
}
}
}
public async placescript(scriptText:string, context?:sqlops.ObjectExplorerContext) {
try {
var connection;
if (context) {
let connection = context.connectionProfile;
this.connectionId = connection.id;
this.dbName = connection.databaseName;
} else {
connection = await sqlops.connection.getCurrentConnection();
if (connection) {
this.connectionId = connection.connectionId;
this.dbName = connection.databaseName;
}
}
let doc = await vscode.workspace.openTextDocument({language: 'sql'});
let editor = await vscode.window.showTextDocument(doc, 1, false);
editor.edit(edit => {
edit.insert(new vscode.Position(0, 0), scriptText);
});
const workbenchConfig = vscode.workspace.getConfiguration('newquerytemplate');
let lineAt: number = workbenchConfig.get('DefaultQueryLine');
let charAt: number = workbenchConfig.get('DefaultQueryCharacter');
if (lineAt >= 0 && charAt >= 0) {
let newPosition: vscode.Position = new vscode.Position(lineAt, charAt);
var useDatabaseCmd = () => {
tH.sendTelemetry('useDatabaseCmd', { }, { });
azdata.connection.getCurrentConnection().then( connection => {
if (connection) {
let databaseList = azdata.connection.listDatabases(connection.connectionId);
changeDatabase(databaseList, connection);
} else {
vscode.window.showErrorMessage("No connection found. Connect before switching databases.");
}
}, error => {
console.info(error);
});
}
var disposable_useDatabase = vscode.commands.registerCommand('dsk.useDatabase', useDatabaseCmd);
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");
}
};
export async function hangOnToConnection(): Promise {
let connectProf = await azdata.connection.getCurrentConnection();
let connectHoldId : string = '';
let dbName: string = '';
let providerId: string = '';
connectHoldId = connectProf.connectionId;
dbName = connectProf.databaseName;
providerId = connectProf.providerId;
return {connectHoldId: connectHoldId, dbName: dbName, providerId: providerId};
}
public async checkForUpdates(context?: sqlops.ObjectExplorerContext): Promise {
let baseUrl = "https://api.github.com/repos/BrentOzarULTD/SQL-Server-First-Responder-Kit/releases/latest";
let apitoken = 'token ' + apiconfig.token;
vscode.window.showInformationMessage("Checking First Responder Kit for Updates");
try {
var connectId;
if (context) {
let connection = context.connectionProfile;
connectId = connection.id;
} else {
let connection = await sqlops.connection.getCurrentConnection();
connectId = connection.connectionId;
}
let query = `declare @versionno datetime
DECLARE @VERSION VARCHAR(30)
IF OBJECT_ID('dbo.sp_Blitz') IS NULL
set @versionno = '1/1/1900'
ELSE
BEGIN
BEGIN TRY
exec sp_blitz @VERSIONCHECKMODE = 1, @VERSION = @VERSION OUTPUT, @versiondate = @versionno output;
END TRY
BEGIN CATCH
exec sp_blitz @help = 1, @versiondate = @versionno output
END CATCH