Skip to content

Commit d560e83

Browse files
committed
Initial work for support parameters
Signed-off-by: worksofliam <mrliamallan@live.co.uk>
1 parent 5b7ccfd commit d560e83

File tree

4 files changed

+45
-22
lines changed

4 files changed

+45
-22
lines changed

package-lock.json

Lines changed: 2 additions & 2 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/views/results/html.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ import { Webview } from "vscode";
22
import { getHeader } from "../html";
33

44
import Configuration from "../../configuration";
5+
import { SqlParameter } from "./resultSetPanelProvider";
56

67
export function setLoadingText(webview: Webview, text: string) {
78
webview.postMessage({
@@ -294,7 +295,7 @@ document.getElementById('resultset').onclick = function(e){
294295
};
295296
`;
296297

297-
export function generateScroller(basicSelect: string, isCL: boolean, withCancel?: boolean, updatable?: UpdatableInfo): string {
298+
export function generateScroller(basicSelect: string, parameters: SqlParameter[] = [], isCL: boolean = false, withCancel: boolean = false, updatable?: UpdatableInfo): string {
298299
const withCollapsed = Configuration.get<boolean>('collapsedResultSet');
299300

300301
return /*html*/`
@@ -417,6 +418,7 @@ export function generateScroller(basicSelect: string, isCL: boolean, withCancel?
417418
isFetching = true;
418419
vscode.postMessage({
419420
query: basicSelect,
421+
parameters: ${JSON.stringify(parameters)},
420422
isCL: ${isCL},
421423
queryId: myQueryId
422424
});

src/views/results/index.ts

Lines changed: 15 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ import { ExplainType } from "../../connection/types";
2020
import { queryResultToRpgDs } from "./codegen";
2121
import Configuration from "../../configuration";
2222

23-
export type StatementQualifier = "statement" | "update" | "explain" | "onlyexplain" | "json" | "csv" | "cl" | "sql" | "rpg";
23+
export type StatementQualifier = "statement" | "bind" | "update" | "explain" | "onlyexplain" | "json" | "csv" | "cl" | "sql" | "rpg";
2424

2525
export interface StatementInfo {
2626
content: string,
@@ -333,10 +333,13 @@ async function runHandler(options?: StatementInfo) {
333333
if (inWindow) {
334334
useWindow(`CL results`, options.viewColumn);
335335
}
336-
chosenView.setScrolling(statementDetail.content, true); // Never errors
336+
chosenView.setScrolling({
337+
basicSelect: statementDetail.content,
338+
isCL: true,
339+
}); // Never errors
337340
}
338341

339-
} else if ([`statement`, `update`].includes(statementDetail.qualifier)) {
342+
} else if ([`statement`, `update`, `cl`].includes(statementDetail.qualifier)) {
340343
// If it's a basic statement, we can let it scroll!
341344
if (statementDetail.noUi) {
342345
setCancelButtonVisibility(true);
@@ -353,7 +356,11 @@ async function runHandler(options?: StatementInfo) {
353356
updatableTable = refs[0];
354357
}
355358

356-
chosenView.setScrolling(statementDetail.content, false, undefined, inWindow, updatableTable); // Never errors
359+
chosenView.setScrolling({ // Never errors
360+
basicSelect: statementDetail.content,
361+
withCancel: inWindow,
362+
ref: updatableTable,
363+
})
357364
}
358365

359366
} else if ([`explain`, `onlyexplain`].includes(statementDetail.qualifier)) {
@@ -372,7 +379,10 @@ async function runHandler(options?: StatementInfo) {
372379
if (onlyExplain) {
373380
chosenView.setLoadingText(`Explained.`, false);
374381
} else {
375-
chosenView.setScrolling(statementDetail.content, false, explained.id); // Never errors
382+
chosenView.setScrolling({ // Never errors
383+
basicSelect: statementDetail.content,
384+
queryId: explained.id,
385+
})
376386
}
377387

378388
explainTree = new ExplainTree(explained.vedata);

src/views/results/resultSetPanelProvider.ts

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,17 @@ import Table from "../../database/table";
1111
import Statement from "../../database/statement";
1212
import { TableColumn } from "../../types";
1313

14+
export type SqlParameter = string|number;
15+
16+
export interface ScrollerOptions {
17+
basicSelect: string;
18+
parameters?: SqlParameter[];
19+
isCL?: boolean;
20+
queryId?: string;
21+
withCancel?: boolean;
22+
ref?: ObjectRef;
23+
}
24+
1425
export class ResultSetPanelProvider implements WebviewViewProvider {
1526
_view: WebviewView | WebviewPanel;
1627
loadingState: boolean;
@@ -193,17 +204,17 @@ export class ResultSetPanelProvider implements WebviewViewProvider {
193204
}
194205
}
195206

196-
async setScrolling(basicSelect: string, isCL = false, queryId: string = ``, withCancel = false, ref?: ObjectRef) {
207+
async setScrolling(options: ScrollerOptions) {
197208
this.loadingState = false;
198209
await this.focus();
199210

200211
let updatable: html.UpdatableInfo | undefined;
201212

202-
if (ref) {
203-
const schema = ref.object.schema || ref.object.system;
213+
if (options.ref) {
214+
const schema = options.ref.object.schema || options.ref.object.system;
204215
if (schema) {
205216
const goodSchema = Statement.delimName(schema, true);
206-
const goodName = Statement.delimName(ref.object.name, true);
217+
const goodName = Statement.delimName(options.ref.object.name, true);
207218

208219
try {
209220
const isPartitioned = await Table.isPartitioned(goodSchema, goodName);
@@ -234,16 +245,16 @@ export class ResultSetPanelProvider implements WebviewViewProvider {
234245
}));
235246

236247
if (!currentColumns.some(c => c.useInWhere)) {
237-
const cName = ref.alias || `t`;
248+
const cName = options.ref.alias || `t`;
238249

239250
// Support for using a custom column list
240-
const selectClauseStart = basicSelect.toLowerCase().indexOf(`select `);
241-
const fromClauseStart = basicSelect.toLowerCase().indexOf(`from`);
251+
const selectClauseStart = options.basicSelect.toLowerCase().indexOf(`select `);
252+
const fromClauseStart = options.basicSelect.toLowerCase().indexOf(`from`);
242253
let possibleColumnList: string | undefined;
243254

244255
possibleColumnList = `${cName}.*`;
245256
if (fromClauseStart > 0) {
246-
possibleColumnList = basicSelect.substring(0, fromClauseStart);
257+
possibleColumnList = options.basicSelect.substring(0, fromClauseStart);
247258
if (selectClauseStart >= 0) {
248259
possibleColumnList = possibleColumnList.substring(selectClauseStart + 7);
249260

@@ -254,20 +265,20 @@ export class ResultSetPanelProvider implements WebviewViewProvider {
254265
}
255266

256267
// We need to override the input statement if they want to do updatable
257-
const whereClauseStart = basicSelect.toLowerCase().indexOf(`where`);
268+
const whereClauseStart = options.basicSelect.toLowerCase().indexOf(`where`);
258269
let fromWhereClause: string | undefined;
259270

260271
if (whereClauseStart > 0) {
261-
fromWhereClause = basicSelect.substring(whereClauseStart);
272+
fromWhereClause = options.basicSelect.substring(whereClauseStart);
262273
}
263274

264275

265-
basicSelect = `select rrn(${cName}) as RRN, ${possibleColumnList} from ${schema}.${ref.object.name} as ${cName} ${fromWhereClause || ``}`;
276+
options.basicSelect = `select rrn(${cName}) as RRN, ${possibleColumnList} from ${schema}.${options.ref.object.name} as ${cName} ${fromWhereClause || ``}`;
266277
currentColumns = [{ name: `RRN`, jsType: `number`, useInWhere: true }, ...currentColumns];
267278
}
268279

269280
updatable = {
270-
table: schema + `.` + ref.object.name,
281+
table: schema + `.` + options.ref.object.name,
271282
columns: currentColumns
272283
};
273284
}
@@ -278,11 +289,11 @@ export class ResultSetPanelProvider implements WebviewViewProvider {
278289
}
279290
}
280291

281-
this._view.webview.html = html.generateScroller(basicSelect, isCL, withCancel, updatable);
292+
this._view.webview.html = html.generateScroller(options.basicSelect, options.parameters, options.isCL, options.withCancel, updatable);
282293

283294
this._view.webview.postMessage({
284295
command: `fetch`,
285-
queryId
296+
queryId: options.queryId
286297
});
287298
}
288299

0 commit comments

Comments
 (0)