diff --git a/src/extension.ts b/src/extension.ts index b075eea..5a773ee 100644 --- a/src/extension.ts +++ b/src/extension.ts @@ -11,6 +11,7 @@ var dbSession = null; // your extension is activated the very first time the command is executed export function activate(context: vscode.ExtensionContext) { const connectionProvider = new ConnectionProvider(); + let myOutputChannel = vscode.window.createOutputChannel('SQL Query Results'); vscode.window.registerTreeDataProvider('connections', connectionProvider); @@ -32,11 +33,7 @@ export function activate(context: vscode.ExtensionContext) { if (selection.isEmpty) return; - let text = editor.document.getText(selection); - - console.log(text); - - let myOutputChannel = vscode.window.createOutputChannel('SQL Query Results'); + let text = editor.document.getText(selection); if (!dbSession) { let extPath = vscode.extensions.getExtension("todie.frog").extensionPath; @@ -53,7 +50,11 @@ export function activate(context: vscode.ExtensionContext) { let cd = json['columnDefinitions'] if (!json['rows']) { - myOutputChannel.append(JSON.stringify(json, null ,2)); + if (!json['userErrors']) { + myOutputChannel.append("SQL executed successfully.\n"); + } else { + myOutputChannel.append(JSON.stringify(json, null ,2)); + } } else { for (let row of json["rows"]) { myOutputChannel.append("--- ROW ---\n"); @@ -63,7 +64,7 @@ export function activate(context: vscode.ExtensionContext) { } } - myOutputChannel.append("-- DATUM HIER -------------------------------\n"); + myOutputChannel.append("-- " + new Date() + " -------------------------------\n"); outputBuffer = ""; } catch (e) {} }); @@ -72,6 +73,11 @@ export function activate(context: vscode.ExtensionContext) { myOutputChannel.show(); myOutputChannel.append(data.toString()); }); + + dbSession.on('close', (code) => { + console.log(`child process exited with code ${code}`); + dbSession = null; + }); } if (!text) { @@ -79,7 +85,7 @@ export function activate(context: vscode.ExtensionContext) { return; } - myOutputChannel.append("-- DATUM HIER -------------------------------\nExecuting: '" + text + "'\n"); + myOutputChannel.append("-- " + new Date() + " -------------------------------\n"); //Executing: '" + text + "'\n"); dbSession.stdin.write(text + "\n--- END ---\n"); });