diff --git a/package.json b/package.json index 62c9c4a6..3d0aae46 100644 --- a/package.json +++ b/package.json @@ -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": [] } } }, @@ -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", @@ -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" @@ -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", diff --git a/src/IBMiDetail.ts b/src/IBMiDetail.ts index a4a961a1..a2528644 100644 --- a/src/IBMiDetail.ts +++ b/src/IBMiDetail.ts @@ -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; } @@ -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([ diff --git a/src/config.ts b/src/config.ts index 1e2f7663..5dfa8cba 100644 --- a/src/config.ts +++ b/src/config.ts @@ -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]; diff --git a/src/connection/extendedSQLJob.ts b/src/connection/extendedSQLJob.ts index 4778255b..26b299a2 100644 --- a/src/connection/extendedSQLJob.ts +++ b/src/connection/extendedSQLJob.ts @@ -1,17 +1,20 @@ 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 getNaming(): undefined | "sql" | "system" - setSelfState(code: SelfValue): Promise + setSelfState(code: SelfValue, excludes?: number[]): Promise getJobLog(): Promise> requestCancel(): Promise } @@ -19,9 +22,11 @@ export type ExtendedSQLJob = SQLJob & { 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`) { @@ -41,8 +46,23 @@ export function extendSQLJob(job: SQLJob) { wrappedJob.getNaming = () => wrappedJob.options.naming; - wrappedJob.setSelfState = async (code: SelfValue) => { - await wrappedJob.query(`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(`SET SYSIBMADM.SELFCODES = '${sqlValue}'`).execute(); wrappedJob.selfState = code; } diff --git a/src/connection/manager.ts b/src/connection/manager.ts index 7574ade5..a7e877d3 100644 --- a/src/connection/manager.ts +++ b/src/connection/manager.ts @@ -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); } } @@ -232,4 +233,8 @@ export class SQLJobManager { static getSelfDefault(): SelfValue { return Configuration.get(`jobManager.jobSelfDefault`) || `*NONE`; } + + static getSelfExcludes(): number[] { + return Configuration.get(`jobManager.jobSelfExcludes`) || []; + } } diff --git a/src/views/jobManager/contributes.json b/src/views/jobManager/contributes.json index 78b2108f..5150c736 100644 --- a/src/views/jobManager/contributes.json +++ b/src/views/jobManager/contributes.json @@ -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": [] } } } @@ -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", @@ -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" @@ -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", diff --git a/src/views/jobManager/jobManagerView.ts b/src/views/jobManager/jobManagerView.ts index 27688623..95553599 100644 --- a/src/views/jobManager/jobManagerView.ts +++ b/src/views/jobManager/jobManagerView.ts @@ -27,7 +27,7 @@ export class JobManagerView implements TreeDataProvider { ...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) => { @@ -189,6 +189,50 @@ export class JobManagerView implements TreeDataProvider { } }), + 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;