From 704a6a9e48f435031dbc4f875f8e9b61fb36bb4c Mon Sep 17 00:00:00 2001 From: ecmel Date: Wed, 22 May 2024 19:52:58 +0300 Subject: [PATCH 1/2] fixes KXI-46574 --- src/commands/dataSourceCommand.ts | 60 ++++++++++++++++--------------- 1 file changed, 31 insertions(+), 29 deletions(-) diff --git a/src/commands/dataSourceCommand.ts b/src/commands/dataSourceCommand.ts index 2a3c3418..02fd2a31 100644 --- a/src/commands/dataSourceCommand.ts +++ b/src/commands/dataSourceCommand.ts @@ -152,35 +152,37 @@ export async function runDataSource( } ext.isDatasourceExecution = false; - if (res.error) { - window.showErrorMessage(res.error); - addDStoQueryHistory(dataSourceForm, false, connLabel, executorName); - } else if (ext.resultsViewProvider.isVisible()) { - ext.outputChannel.appendLine( - `Results: ${typeof res === "string" ? "0" : res.rows.length} rows`, - ); - addDStoQueryHistory(dataSourceForm, true, connLabel, executorName); - writeQueryResultsToView( - res, - getQuery(fileContent, selectedType), - connLabel, - executorName, - true, - selectedType, - ); - } else { - ext.outputChannel.appendLine( - `Results is a string with length: ${res.length}`, - ); - addDStoQueryHistory(dataSourceForm, true, connLabel, executorName); - writeQueryResultsToConsole( - res, - getQuery(fileContent, selectedType), - connLabel, - executorName, - true, - selectedType, - ); + if (res) { + if (res.error) { + window.showErrorMessage(res.error); + addDStoQueryHistory(dataSourceForm, false, connLabel, executorName); + } else if (ext.resultsViewProvider.isVisible()) { + ext.outputChannel.appendLine( + `Results: ${typeof res === "string" ? "0" : res.rows.length} rows`, + ); + addDStoQueryHistory(dataSourceForm, true, connLabel, executorName); + writeQueryResultsToView( + res, + getQuery(fileContent, selectedType), + connLabel, + executorName, + true, + selectedType, + ); + } else { + ext.outputChannel.appendLine( + `Results is a string with length: ${res.length}`, + ); + addDStoQueryHistory(dataSourceForm, true, connLabel, executorName); + writeQueryResultsToConsole( + res, + getQuery(fileContent, selectedType), + connLabel, + executorName, + true, + selectedType, + ); + } } } catch (error) { window.showErrorMessage((error as Error).message); From 03201cfa04d64a002d9629f969c103cf341dee23 Mon Sep 17 00:00:00 2001 From: ecmel Date: Thu, 23 May 2024 10:30:12 +0300 Subject: [PATCH 2/2] optimized code --- src/commands/dataSourceCommand.ts | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/commands/dataSourceCommand.ts b/src/commands/dataSourceCommand.ts index 02fd2a31..ce5275b7 100644 --- a/src/commands/dataSourceCommand.ts +++ b/src/commands/dataSourceCommand.ts @@ -153,17 +153,17 @@ export async function runDataSource( ext.isDatasourceExecution = false; if (res) { - if (res.error) { + const success = !res.error; + const query = getQuery(fileContent, selectedType); + + if (!success) { window.showErrorMessage(res.error); - addDStoQueryHistory(dataSourceForm, false, connLabel, executorName); } else if (ext.resultsViewProvider.isVisible()) { - ext.outputChannel.appendLine( - `Results: ${typeof res === "string" ? "0" : res.rows.length} rows`, - ); - addDStoQueryHistory(dataSourceForm, true, connLabel, executorName); + const resultCount = typeof res === "string" ? "0" : res.rows.length; + ext.outputChannel.appendLine(`Results: ${resultCount} rows`); writeQueryResultsToView( res, - getQuery(fileContent, selectedType), + query, connLabel, executorName, true, @@ -173,16 +173,16 @@ export async function runDataSource( ext.outputChannel.appendLine( `Results is a string with length: ${res.length}`, ); - addDStoQueryHistory(dataSourceForm, true, connLabel, executorName); writeQueryResultsToConsole( res, - getQuery(fileContent, selectedType), + query, connLabel, executorName, true, selectedType, ); } + addDStoQueryHistory(dataSourceForm, success, connLabel, executorName); } } catch (error) { window.showErrorMessage((error as Error).message);