Skip to content
Open
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
25 changes: 25 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,16 @@
"*ERROR",
"*WARNING"
]
},
"vscode-db2i.jobManager.jobSelfExcludes": {
"type": "array",
"order": 2,
"description": "Default SQLCODE values to exclude from SELF tracking (up to 32 values)",
"items": {
"type": "number",
"description": "The SQLCODE to exclude from SELF tracking"
},
"default": []
}
}
},
Expand Down Expand Up @@ -1024,6 +1034,12 @@
"category": "Db2 for i",
"icon": "$(bracket-error)"
},
{
"command": "vscode-db2i.jobManager.editSelfExcludes",
"title": "Set excludes for SELF",
"category": "Db2 for i",
"icon": "$(filter)"
},
{
"command": "vscode-db2i.jobManager.copyJobId",
"title": "Copy Job Name",
Expand Down Expand Up @@ -1405,6 +1421,10 @@
"command": "vscode-db2i.jobManager.editSelfCodes",
"when": "never"
},
{
"command": "vscode-db2i.jobManager.editSelfExcludes",
"when": "never"
},
{
"command": "vscode-db2i.jobManager.copyJobId",
"when": "never"
Expand Down Expand Up @@ -1837,6 +1857,11 @@
"when": "view == jobManager && viewItem == sqlJob",
"group": "self@2"
},
{
"command": "vscode-db2i.jobManager.editSelfExcludes",
"when": "view == jobManager && viewItem == sqlJob && (vscode-db2i:7.5 || vscode-db2i:7.6)",
"group": "self@3"
},
{
"command": "vscode-db2i.jobManager.copyJobId",
"when": "view == jobManager && viewItem == sqlJob",
Expand Down
7 changes: 6 additions & 1 deletion src/IBMiDetail.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,11 @@ export class IBMiDetail {
commands.executeCommand(`setContext`, `vscode-db2i:${featureId}Supported`, supported);
}

setVersion(version: string) {
this.version = version;
commands.executeCommand(`setContext`, `vscode-db2i:${version}`, true);
}

getVersion() {
return this.version;
}
Expand All @@ -44,7 +49,7 @@ export class IBMiDetail {
let levelCheckFailed = false;

const versionResults = await connection.runSQL(`SELECT CAST(SUBSTR(DATA_AREA_VALUE, 2, 1) CONCAT '.' CONCAT SUBSTR(DATA_AREA_VALUE, 4, 1) AS VARCHAR(32)) AS OS_VERSION FROM TABLE (QSYS2.DATA_AREA_INFO('QSS1MRI', '*LIBL'))`);
this.version = String(versionResults[0].OS_VERSION);
this.setVersion(String(versionResults[0].OS_VERSION));

try {
const db2LevelResults = await connection.runSQL([
Expand Down
1 change: 1 addition & 0 deletions src/config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ export function initConfig(context: ExtensionContext) {
JobManagerView.setVisible(false);
await JobManager.reset();
updateStatusBar();
commands.executeCommand(`setContext`, `vscode-db2i:${osDetail?.getVersion()}`, false);

// Remove old service examples
delete Examples[ServiceInfoLabel];
Expand Down
30 changes: 25 additions & 5 deletions src/connection/extendedSQLJob.ts
Original file line number Diff line number Diff line change
@@ -1,27 +1,32 @@
import { SQLJob } from "@ibm/mapepire-js";
import { QueryResult } from "@ibm/mapepire-js/dist/src/types";
import { getInstance } from "../base";
import { osDetail } from "../config";
import { SelfValue } from "../views/jobManager/selfCodes/nodes";
import { JobLogEntry } from "./types";

export type ExtendedSQLJob = SQLJob & {
selfState: SelfValue
currentSchemaStore?: string
selfState: SelfValue;
selfExcludes: number[];
currentSchemaStore?: string;
resetCurrentSchemaCache(): void
getSelfCode(): SelfValue
getSelfExcludes(): number[]
getCurrentSchema(): Promise<string>
getNaming(): undefined | "sql" | "system"
setSelfState(code: SelfValue): Promise<void>
setSelfState(code: SelfValue, excludes?: number[]): Promise<void>
getJobLog(): Promise<QueryResult<JobLogEntry>>
requestCancel(): Promise<boolean>
}

export function extendSQLJob(job: SQLJob) {
const wrappedJob = job as ExtendedSQLJob;
wrappedJob.selfState = "*NONE";
wrappedJob.selfExcludes = [];

wrappedJob.resetCurrentSchemaCache = () => delete wrappedJob.currentSchemaStore;
wrappedJob.getSelfCode = () => wrappedJob.selfState;
wrappedJob.getSelfExcludes = () => wrappedJob.selfExcludes;

wrappedJob.getCurrentSchema = async () => {
if (wrappedJob.getNaming() === `sql`) {
Expand All @@ -41,8 +46,23 @@ export function extendSQLJob(job: SQLJob) {

wrappedJob.getNaming = () => wrappedJob.options.naming;

wrappedJob.setSelfState = async (code: SelfValue) => {
await wrappedJob.query<any>(`SET SYSIBMADM.SELFCODES = '${code}'`).execute();
wrappedJob.setSelfState = async (code: SelfValue, excludes?: number[]) => {
if (excludes !== undefined) {
wrappedJob.selfExcludes = excludes;
}

let sqlValue: string = code;
if (
code !== `*NONE` &&
osDetail &&
Number(osDetail.getVersion()) >= 7.6 &&
wrappedJob.selfExcludes.length > 0
) {
const excludeList = wrappedJob.selfExcludes.slice(0, 32).join(`,`);
sqlValue = `${code} EXCLUDING ${excludeList}`;
}

await wrappedJob.query<any>(`SET SYSIBMADM.SELFCODES = '${sqlValue}'`).execute();
wrappedJob.selfState = code;
}

Expand Down
7 changes: 6 additions & 1 deletion src/connection/manager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -75,8 +75,9 @@ export class SQLJobManager {
if (osDetail) {
const features = osDetail.getFeatures();
const selfDefault = SQLJobManager.getSelfDefault();
const selfExcludes = SQLJobManager.getSelfExcludes();
if (features.SELF && selfDefault !== `*NONE`) {
await newJob.setSelfState(selfDefault);
await newJob.setSelfState(selfDefault, selfExcludes);
}
}

Expand Down Expand Up @@ -232,4 +233,8 @@ export class SQLJobManager {
static getSelfDefault(): SelfValue {
return Configuration.get<SelfValue>(`jobManager.jobSelfDefault`) || `*NONE`;
}

static getSelfExcludes(): number[] {
return Configuration.get<number[]>(`jobManager.jobSelfExcludes`) || [];
}
}
25 changes: 25 additions & 0 deletions src/views/jobManager/contributes.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,16 @@
"*ERROR",
"*WARNING"
]
},
"vscode-db2i.jobManager.jobSelfExcludes": {
"type": "array",
"order": 2,
"description": "Default SQLCODE values to exclude from SELF tracking (up to 32 values)",
"items": {
"type": "number",
"description": "The SQLCODE to exclude from SELF tracking"
},
"default": []
}
}
}
Expand Down Expand Up @@ -101,6 +111,12 @@
"category": "Db2 for i",
"icon": "$(bracket-error)"
},
{
"command": "vscode-db2i.jobManager.editSelfExcludes",
"title": "Set excludes for SELF",
"category": "Db2 for i",
"icon": "$(filter)"
},
{
"command": "vscode-db2i.jobManager.copyJobId",
"title": "Copy Job Name",
Expand Down Expand Up @@ -182,6 +198,10 @@
"command": "vscode-db2i.jobManager.editSelfCodes",
"when": "never"
},
{
"command": "vscode-db2i.jobManager.editSelfExcludes",
"when": "never"
},
{
"command": "vscode-db2i.jobManager.copyJobId",
"when": "never"
Expand Down Expand Up @@ -262,6 +282,11 @@
"when": "view == jobManager && viewItem == sqlJob",
"group": "self@2"
},
{
"command": "vscode-db2i.jobManager.editSelfExcludes",
"when": "view == jobManager && viewItem == sqlJob && (vscode-db2i:7.5 || vscode-db2i:7.6)",
"group": "self@3"
},
{
"command": "vscode-db2i.jobManager.copyJobId",
"when": "view == jobManager && viewItem == sqlJob",
Expand Down
46 changes: 45 additions & 1 deletion src/views/jobManager/jobManagerView.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export class JobManagerView implements TreeDataProvider<any> {
...ConfigManager.initialiseSaveCommands(),

vscode.commands.registerCommand(`vscode-db2i.jobManager.editDefaultSelf`, () => {
vscode.commands.executeCommand('workbench.action.openSettings', 'vscode-db2i.jobManager.jobSelfDefault');
vscode.commands.executeCommand('workbench.action.openSettings', 'vscode-db2i.jobManager.jobSelf');
}),

vscode.commands.registerCommand(`vscode-db2i.jobManager.newJob`, async (options?: JDBCOptions, name?: string) => {
Expand Down Expand Up @@ -189,6 +189,50 @@ export class JobManagerView implements TreeDataProvider<any> {
}
}),

vscode.commands.registerCommand(`vscode-db2i.jobManager.editSelfExcludes`, async (node?: SQLJobItem) => {
const id = node ? node.label as string : undefined;
let selected = id ? JobManager.getJob(id) : JobManager.getSelection();
if (selected) {
try {
const currentExcludes = selected.job.getSelfExcludes();
const currentExcludesString = currentExcludes.join(`, `);
const input = await vscode.window.showInputBox({
title: `Set SQL codes to exclude from SELF`,
prompt: `Enter a comma-separated list of up to 32 SQLCODE values to exclude (e.g. -204, -501)`,
placeHolder: `SQLCODE values to exclude`,
value: currentExcludesString,
validateInput: (value) => {
if (!value.trim()) {
return null;
}
const parts = value.split(/[\s,]+/).filter(Boolean);
if (parts.length > 32) {
return `A maximum of 32 SQLCODE values can be excluded.`;
}
for (const part of parts) {
if (isNaN(Number(part)) || !Number.isInteger(Number(part))) {
return `Invalid SQLCODE: '${part}'. SQLCODEs must be integers (e.g. -204).`;
}
}
return null;
}
});

if (input !== undefined) {
const codes = input.trim() ? input.split(/[\s,]+/).filter(Boolean).map(Number) : [];
try {
await selected.job.setSelfState(selected.job.getSelfCode(), codes);
vscode.window.showInformationMessage(`Applied excluded SELF codes: ${codes.join(`, `) || `none`}`);
} catch (e: any) {
vscode.window.showErrorMessage(`Cannot set excluded SELF codes: ${e.message || e}`);
}
}
} catch (e: any) {
vscode.window.showErrorMessage(e.message);
}
}
}),

vscode.commands.registerCommand(`vscode-db2i.jobManager.enableTracing`, async (node?: SQLJobItem) => {
if (node) {
const id = node.label as string;
Expand Down
Loading