Skip to content

Commit 8181e05

Browse files
authored
Adding a setting to prevent auto execute on Select top 1000 (#20224)
1 parent 4f457d5 commit 8181e05

File tree

5 files changed

+31
-14
lines changed

5 files changed

+31
-14
lines changed

localization/xliff/vscode-mssql.xlf

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3786,6 +3786,9 @@
37863786
<trans-unit id="mssql.pauseQueryHistoryCapture">
37873787
<source xml:lang="en">Pause Query History Capture</source>
37883788
</trans-unit>
3789+
<trans-unit id="mssql.preventAutoExecuteScript">
3790+
<source xml:lang="en">Prevent automatic execution of scripts (e.g., &apos;Select Top 1000&apos;). When enabled, scripts will not be automatically executed upon generation.</source>
3791+
</trans-unit>
37893792
<trans-unit id="mssql.authCodeGrant.description">
37903793
<source xml:lang="en">Prompts users to sign in using their browser.</source>
37913794
</trans-unit>

package.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1689,6 +1689,12 @@
16891689
],
16901690
"scope": "resource"
16911691
},
1692+
"mssql.query.preventAutoExecuteScript": {
1693+
"type": "boolean",
1694+
"description": "%mssql.preventAutoExecuteScript%",
1695+
"default": false,
1696+
"scope": "resource"
1697+
},
16921698
"mssql.enableSqlAuthenticationProvider": {
16931699
"type": "boolean",
16941700
"description": "%mssql.enableSqlAuthenticationProvider%",

package.nls.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@
115115
"mssql.copyRemoveNewLine": "[Optional] Configuration options for copying multi-line results from the Results View",
116116
"mssql.showBatchTime": "[Optional] Should execution time be shown for individual batches",
117117
"mssql.splitPaneSelection": "[Optional] Configuration options for which column new result panes should open in",
118+
"mssql.preventAutoExecuteScript": "Prevent automatic execution of scripts (e.g., 'Select Top 1000'). When enabled, scripts will not be automatically executed upon generation.",
118119
"mssql.format.alignColumnDefinitionsInColumns": "Should column definitions be aligned?",
119120
"mssql.format.datatypeCasing": "Should data types be formatted as UPPERCASE, lowercase, or none (not formatted)",
120121
"mssql.format.keywordCasing": "Should keywords be formatted as UPPERCASE, lowercase, or none (not formatted)",

src/constants/constants.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,7 @@ export const configMaxRecentConnections = "maxRecentConnections";
206206
export const configCopyRemoveNewLine = "copyRemoveNewLine";
207207
export const configSplitPaneSelection = "splitPaneSelection";
208208
export const configShowBatchTime = "showBatchTime";
209+
export const configPreventAutoExecuteScript = "mssql.query.preventAutoExecuteScript";
209210
export enum extConfigResultKeys {
210211
Shortcuts = "shortcuts",
211212
MessagesDefaultOpen = "messagesDefaultOpen",

src/controllers/mainController.ts

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -736,20 +736,26 @@ export default class MainController implements vscode.Disposable {
736736
connectionInfo: connectionCreds,
737737
});
738738
if (executeScript) {
739-
const uri = getUriKey(editor.document.uri);
740-
const queryPromise = new Deferred<boolean>();
741-
await this._outputContentProvider.runQuery(
742-
this._statusview,
743-
uri,
744-
undefined,
745-
title,
746-
undefined,
747-
queryPromise,
748-
);
749-
await queryPromise;
750-
await this.connectionManager.connectionStore.removeRecentlyUsed(
751-
<IConnectionProfile>connectionCreds,
752-
);
739+
const preventAutoExecute = vscode.workspace
740+
.getConfiguration()
741+
.get<boolean>(Constants.configPreventAutoExecuteScript);
742+
743+
if (!preventAutoExecute) {
744+
const uri = getUriKey(editor.document.uri);
745+
const queryPromise = new Deferred<boolean>();
746+
await this._outputContentProvider.runQuery(
747+
this._statusview,
748+
uri,
749+
undefined,
750+
title,
751+
undefined,
752+
queryPromise,
753+
);
754+
await queryPromise;
755+
await this.connectionManager.connectionStore.removeRecentlyUsed(
756+
<IConnectionProfile>connectionCreds,
757+
);
758+
}
753759
}
754760

755761
let scriptType;

0 commit comments

Comments
 (0)