Skip to content

Commit 0d509d7

Browse files
authored
Merge pull request #352 from codefori/feature/run_multiple
Ability to run multiple statements
2 parents 69d7c08 + 67644d2 commit 0d509d7

File tree

5 files changed

+252
-59
lines changed

5 files changed

+252
-59
lines changed

package.json

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -436,6 +436,21 @@
436436
"category": "Db2 for i",
437437
"icon": "$(window)"
438438
},
439+
{
440+
"command": "vscode-db2i.runEditorStatement.multiple.all",
441+
"title": "Run all statements",
442+
"category": "Db2 for i"
443+
},
444+
{
445+
"command": "vscode-db2i.runEditorStatement.multiple.selected",
446+
"title": "Run selected statements",
447+
"category": "Db2 for i"
448+
},
449+
{
450+
"command": "vscode-db2i.runEditorStatement.multiple.from",
451+
"title": "Run statements from cursor",
452+
"category": "Db2 for i"
453+
},
439454
{
440455
"command": "vscode-db2i.statement.cancel",
441456
"title": "Cancel",
@@ -1118,22 +1133,37 @@
11181133
{
11191134
"command": "vscode-db2i.runEditorStatement.inView",
11201135
"when": "editorLangId == sql && vscode-db2i:statementCanCancel != true",
1121-
"group": "navigation@1"
1136+
"group": "navigation@2"
1137+
},
1138+
{
1139+
"command": "vscode-db2i.runEditorStatement.multiple.all",
1140+
"when": "editorLangId == sql && vscode-db2i:statementCanCancel != true",
1141+
"group": "navigation_multiple@1"
1142+
},
1143+
{
1144+
"command": "vscode-db2i.runEditorStatement.multiple.selected",
1145+
"when": "editorLangId == sql && vscode-db2i:statementCanCancel != true && editorHasSelection",
1146+
"group": "navigation_multiple@2"
1147+
},
1148+
{
1149+
"command": "vscode-db2i.runEditorStatement.multiple.from",
1150+
"when": "editorLangId == sql && vscode-db2i:statementCanCancel != true && !editorHasSelection",
1151+
"group": "navigation_multiple@2"
11221152
},
11231153
{
11241154
"command": "vscode-db2i.editorExplain.withRun",
11251155
"when": "editorLangId == sql",
1126-
"group": "2_explain@1"
1156+
"group": "navigation_explain@1"
11271157
},
11281158
{
11291159
"command": "vscode-db2i.editorExplain.withoutRun",
11301160
"when": "editorLangId == sql",
1131-
"group": "2_explain@2"
1161+
"group": "navigation_explain@2"
11321162
},
11331163
{
11341164
"command": "vscode-db2i.notebook.fromSqlUri",
11351165
"when": "editorLangId == sql",
1136-
"group": "3_notebook@1"
1166+
"group": "navigation_notebook@1"
11371167
}
11381168
],
11391169
"notebook/toolbar": [

src/connection/manager.ts

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import { OldSQLJob } from "./sqlJob";
55
import { askAboutNewJob, onConnectOrServerInstall, osDetail } from "../config";
66
import { SelfValue } from "../views/jobManager/selfCodes/nodes";
77
import Configuration from "../configuration";
8-
import { QueryOptions } from "@ibm/mapepire-js/dist/src/types";
8+
import { QueryOptions, QueryResult } from "@ibm/mapepire-js/dist/src/types";
99
import { Query } from "@ibm/mapepire-js/dist/src/query";
1010

1111
export interface JobInfo {
@@ -115,25 +115,27 @@ export class SQLJobManager {
115115
return this.jobs[jobExists];
116116
}
117117

118-
/**
119-
* Runs SQL
120-
* @param query the SQL query
121-
* @param parameters the list of parameters (indicated by '?' parameter parkers in the SQL query)
122-
* @param isTerseResults whether the returned data is in terse format. When set to true, the data is returned as an array
123-
* of arrays. When set to false, data is returned as an array of objects (compatible with legacy API).
124-
* @returns
125-
*/
126-
async runSQL<T>(query: string, opts?: QueryOptions): Promise<T[]> {
118+
async runSQL<T>(query: string, opts?: QueryOptions, rowsToFetch = 2147483647): Promise<T[]> {
127119
// 2147483647 is NOT arbitrary. On the server side, this is processed as a Java
128120
// int. This is the largest number available without overflow (Integer.MAX_VALUE)
129-
const rowsToFetch = 2147483647;
130121

131122
const statement = await this.getPagingStatement<T>(query, opts);
132123
const results = await statement.execute(rowsToFetch);
133124
statement.close();
134125
return results.data;
135126
}
136127

128+
async runSQLVerbose<T>(query: string, opts?: QueryOptions, rowsToFetch = 2147483647): Promise<QueryResult<T>> {
129+
// 2147483647 is NOT arbitrary. On the server side, this is processed as a Java
130+
// int. This is the largest number available without overflow (Integer.MAX_VALUE)
131+
132+
const statement = await this.getPagingStatement<T>(query, opts);
133+
const results = await statement.execute(rowsToFetch);
134+
statement.close();
135+
136+
return results;
137+
}
138+
137139
async getPagingStatement<T>(query: string, opts?: QueryOptions): Promise<Query<T>> {
138140
const selected = this.jobs[this.selectedJob]
139141
if (ServerComponent.isInstalled() && selected) {

src/language/providers/problemProvider.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { commands, CompletionItemKind, Diagnostic, DiagnosticSeverity, languages, ProgressLocation, Range, TextDocument, Uri, window, workspace } from "vscode";
1+
import { commands, CompletionItemKind, Diagnostic, Disposable, DiagnosticSeverity, languages, ProgressLocation, Range, TextDocument, Uri, window, workspace } from "vscode";
22
import {
33
SQLType,
44
} from "../../database/schemas";
@@ -73,7 +73,9 @@ export const checkDocumentDefintion = commands.registerCommand(CHECK_DOCUMENT_CO
7373
}
7474
});
7575

76-
export const problemProvider = [
76+
export const problemProvider: Disposable[] = [
77+
sqlDiagnosticCollection,
78+
7779
workspace.onDidCloseTextDocument(e => {
7880
// Only clear errors from unsaved files.
7981
if (e.isUntitled) {

src/views/results/contributes.json

Lines changed: 34 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,21 @@
5151
"category": "Db2 for i",
5252
"icon": "$(window)"
5353
},
54+
{
55+
"command": "vscode-db2i.runEditorStatement.multiple.all",
56+
"title": "Run all statements",
57+
"category": "Db2 for i"
58+
},
59+
{
60+
"command": "vscode-db2i.runEditorStatement.multiple.selected",
61+
"title": "Run selected statements",
62+
"category": "Db2 for i"
63+
},
64+
{
65+
"command": "vscode-db2i.runEditorStatement.multiple.from",
66+
"title": "Run statements from cursor",
67+
"category": "Db2 for i"
68+
},
5469
{
5570
"command": "vscode-db2i.statement.cancel",
5671
"title": "Cancel",
@@ -111,22 +126,37 @@
111126
{
112127
"command": "vscode-db2i.runEditorStatement.inView",
113128
"when": "editorLangId == sql && vscode-db2i:statementCanCancel != true",
114-
"group": "navigation@1"
129+
"group": "navigation@2"
130+
},
131+
{
132+
"command": "vscode-db2i.runEditorStatement.multiple.all",
133+
"when": "editorLangId == sql && vscode-db2i:statementCanCancel != true",
134+
"group": "navigation_multiple@1"
135+
},
136+
{
137+
"command": "vscode-db2i.runEditorStatement.multiple.selected",
138+
"when": "editorLangId == sql && vscode-db2i:statementCanCancel != true && editorHasSelection",
139+
"group": "navigation_multiple@2"
140+
},
141+
{
142+
"command": "vscode-db2i.runEditorStatement.multiple.from",
143+
"when": "editorLangId == sql && vscode-db2i:statementCanCancel != true && !editorHasSelection",
144+
"group": "navigation_multiple@2"
115145
},
116146
{
117147
"command": "vscode-db2i.editorExplain.withRun",
118148
"when": "editorLangId == sql",
119-
"group": "2_explain@1"
149+
"group": "navigation_explain@1"
120150
},
121151
{
122152
"command": "vscode-db2i.editorExplain.withoutRun",
123153
"when": "editorLangId == sql",
124-
"group": "2_explain@2"
154+
"group": "navigation_explain@2"
125155
},
126156
{
127157
"command": "vscode-db2i.notebook.fromSqlUri",
128158
"when": "editorLangId == sql",
129-
"group": "3_notebook@1"
159+
"group": "navigation_notebook@1"
130160
}
131161
],
132162
"view/title": [

0 commit comments

Comments
 (0)