Skip to content

Ability to run multiple statements #352

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
Mar 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 34 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,21 @@
"category": "Db2 for i",
"icon": "$(window)"
},
{
"command": "vscode-db2i.runEditorStatement.multiple.all",
"title": "Run all statements",
"category": "Db2 for i"
},
{
"command": "vscode-db2i.runEditorStatement.multiple.selected",
"title": "Run selected statements",
"category": "Db2 for i"
},
{
"command": "vscode-db2i.runEditorStatement.multiple.from",
"title": "Run statements from cursor",
"category": "Db2 for i"
},
{
"command": "vscode-db2i.statement.cancel",
"title": "Cancel",
Expand Down Expand Up @@ -1118,22 +1133,37 @@
{
"command": "vscode-db2i.runEditorStatement.inView",
"when": "editorLangId == sql && vscode-db2i:statementCanCancel != true",
"group": "navigation@1"
"group": "navigation@2"
},
{
"command": "vscode-db2i.runEditorStatement.multiple.all",
"when": "editorLangId == sql && vscode-db2i:statementCanCancel != true",
"group": "navigation_multiple@1"
},
{
"command": "vscode-db2i.runEditorStatement.multiple.selected",
"when": "editorLangId == sql && vscode-db2i:statementCanCancel != true && editorHasSelection",
"group": "navigation_multiple@2"
},
{
"command": "vscode-db2i.runEditorStatement.multiple.from",
"when": "editorLangId == sql && vscode-db2i:statementCanCancel != true && !editorHasSelection",
"group": "navigation_multiple@2"
},
{
"command": "vscode-db2i.editorExplain.withRun",
"when": "editorLangId == sql",
"group": "2_explain@1"
"group": "navigation_explain@1"
},
{
"command": "vscode-db2i.editorExplain.withoutRun",
"when": "editorLangId == sql",
"group": "2_explain@2"
"group": "navigation_explain@2"
},
{
"command": "vscode-db2i.notebook.fromSqlUri",
"when": "editorLangId == sql",
"group": "3_notebook@1"
"group": "navigation_notebook@1"
}
],
"notebook/toolbar": [
Expand Down
24 changes: 13 additions & 11 deletions src/connection/manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { OldSQLJob } from "./sqlJob";
import { askAboutNewJob, onConnectOrServerInstall, osDetail } from "../config";
import { SelfValue } from "../views/jobManager/selfCodes/nodes";
import Configuration from "../configuration";
import { QueryOptions } from "@ibm/mapepire-js/dist/src/types";
import { QueryOptions, QueryResult } from "@ibm/mapepire-js/dist/src/types";
import { Query } from "@ibm/mapepire-js/dist/src/query";

export interface JobInfo {
Expand Down Expand Up @@ -115,25 +115,27 @@ export class SQLJobManager {
return this.jobs[jobExists];
}

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

const statement = await this.getPagingStatement<T>(query, opts);
const results = await statement.execute(rowsToFetch);
statement.close();
return results.data;
}

async runSQLVerbose<T>(query: string, opts?: QueryOptions, rowsToFetch = 2147483647): Promise<QueryResult<T>> {
// 2147483647 is NOT arbitrary. On the server side, this is processed as a Java
// int. This is the largest number available without overflow (Integer.MAX_VALUE)

const statement = await this.getPagingStatement<T>(query, opts);
const results = await statement.execute(rowsToFetch);
statement.close();

return results;
}

async getPagingStatement<T>(query: string, opts?: QueryOptions): Promise<Query<T>> {
const selected = this.jobs[this.selectedJob]
if (ServerComponent.isInstalled() && selected) {
Expand Down
6 changes: 4 additions & 2 deletions src/language/providers/problemProvider.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { commands, CompletionItemKind, Diagnostic, DiagnosticSeverity, languages, ProgressLocation, Range, TextDocument, Uri, window, workspace } from "vscode";
import { commands, CompletionItemKind, Diagnostic, Disposable, DiagnosticSeverity, languages, ProgressLocation, Range, TextDocument, Uri, window, workspace } from "vscode";
import {
SQLType,
} from "../../database/schemas";
Expand Down Expand Up @@ -73,7 +73,9 @@ export const checkDocumentDefintion = commands.registerCommand(CHECK_DOCUMENT_CO
}
});

export const problemProvider = [
export const problemProvider: Disposable[] = [
sqlDiagnosticCollection,

workspace.onDidCloseTextDocument(e => {
// Only clear errors from unsaved files.
if (e.isUntitled) {
Expand Down
38 changes: 34 additions & 4 deletions src/views/results/contributes.json
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,21 @@
"category": "Db2 for i",
"icon": "$(window)"
},
{
"command": "vscode-db2i.runEditorStatement.multiple.all",
"title": "Run all statements",
"category": "Db2 for i"
},
{
"command": "vscode-db2i.runEditorStatement.multiple.selected",
"title": "Run selected statements",
"category": "Db2 for i"
},
{
"command": "vscode-db2i.runEditorStatement.multiple.from",
"title": "Run statements from cursor",
"category": "Db2 for i"
},
{
"command": "vscode-db2i.statement.cancel",
"title": "Cancel",
Expand Down Expand Up @@ -111,22 +126,37 @@
{
"command": "vscode-db2i.runEditorStatement.inView",
"when": "editorLangId == sql && vscode-db2i:statementCanCancel != true",
"group": "navigation@1"
"group": "navigation@2"
},
{
"command": "vscode-db2i.runEditorStatement.multiple.all",
"when": "editorLangId == sql && vscode-db2i:statementCanCancel != true",
"group": "navigation_multiple@1"
},
{
"command": "vscode-db2i.runEditorStatement.multiple.selected",
"when": "editorLangId == sql && vscode-db2i:statementCanCancel != true && editorHasSelection",
"group": "navigation_multiple@2"
},
{
"command": "vscode-db2i.runEditorStatement.multiple.from",
"when": "editorLangId == sql && vscode-db2i:statementCanCancel != true && !editorHasSelection",
"group": "navigation_multiple@2"
},
{
"command": "vscode-db2i.editorExplain.withRun",
"when": "editorLangId == sql",
"group": "2_explain@1"
"group": "navigation_explain@1"
},
{
"command": "vscode-db2i.editorExplain.withoutRun",
"when": "editorLangId == sql",
"group": "2_explain@2"
"group": "navigation_explain@2"
},
{
"command": "vscode-db2i.notebook.fromSqlUri",
"when": "editorLangId == sql",
"group": "3_notebook@1"
"group": "navigation_notebook@1"
}
],
"view/title": [
Expand Down
Loading
Loading