Skip to content

Commit

Permalink
Merge pull request #2 from dzsquared/db-dashboard-connection
Browse files Browse the repository at this point in the history
fixes #1
  • Loading branch information
dzsquared authored Sep 7, 2019
2 parents 971c0e8 + 600c316 commit ccf4cdd
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 10 deletions.
7 changes: 3 additions & 4 deletions src/extension.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ export function activate(context: vscode.ExtensionContext) {
var disposable_createQueryTemplate = vscode.commands.registerCommand('dsk.createQueryTemplate', createQueryTemplate);
context.subscriptions.push(disposable_createQueryTemplate);

var newQueryOption = async () => {
var newQueryOption = async (profile?: azdata.IConnectionProfile, context?: azdata.ObjectExplorerContext) => {
let scriptText:string = "";
const workbenchConfig = vscode.workspace.getConfiguration('newquerytemplate');
let queryTemplateArray = new Array<String>();
Expand All @@ -44,11 +44,10 @@ export function activate(context: vscode.ExtensionContext) {
`;
});
}

new placeScript().placescript(scriptText);
new placeScript().placescript(scriptText, profile, context);
};
vscode.commands.registerCommand('dsk.newqueryoption', newQueryOption);
azdata.tasks.registerTask('dsk.newqueryoption', newQueryOption);
azdata.tasks.registerTask('dsk.newqueryoption', (profile?: azdata.IConnectionProfile, context?: azdata.ObjectExplorerContext) => newQueryOption(profile, context));


var useDatabaseCmd = () => {
Expand Down
40 changes: 34 additions & 6 deletions src/placescript.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,46 @@ import * as sqlops from 'azdata';
import * as vscode from 'vscode';

export class placeScript {

private connectionId: string = '';
private dbName: string = '';

// places scriptText into fileName editor with current connection
public async placescript(scriptText) {
public async placescript(scriptText:string, context?:sqlops.IConnectionProfile, oecontext?: sqlops.ObjectExplorerContext) {
try {
let connection = await sqlops.connection.getCurrentConnection();
var connection;
vscode.window.showInformationMessage('starting placescript');
if (context && context.id) {
this.connectionId = context.id;
this.dbName = context.databaseName;
} else if (oecontext) {
connection = oecontext.connectionProfile;
this.connectionId = connection.id;
} 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);
});

if (connection.connectionId) {
await sqlops.queryeditor.connect(doc.uri.toString(), connection.connectionId);
if ((context || connection) && this.connectionId) {
if (this.dbName !== '') {
var providerName:string;
if (context) {
providerName = context.providerName;
} else if (connection) {
providerName = connection.providerId;
}
let dProvider = await sqlops.dataprotocol.getProvider<sqlops.ConnectionProvider>(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);
Expand All @@ -36,7 +64,7 @@ export class placeScript {
editor.edit(edit => {
edit.insert(new vscode.Position(0, 0), scriptText);
});
if (connection.connectionId) {
if (connection.connectionId) {
await sqlops.queryeditor.connect(doc.uri.toString(), connection.connectionId);
}
} catch (err) {
Expand Down

0 comments on commit ccf4cdd

Please sign in to comment.