From 42b23a13c9b5155e1f062faf998cff1f3b9e7a3f Mon Sep 17 00:00:00 2001 From: Seb Julliand Date: Fri, 27 Dec 2024 15:21:20 +0100 Subject: [PATCH 1/3] Replaced deprecated calls Signed-off-by: Seb Julliand --- src/components/getMemberInfo.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/components/getMemberInfo.ts b/src/components/getMemberInfo.ts index c1ee97c01..1d2215cd9 100644 --- a/src/components/getMemberInfo.ts +++ b/src/components/getMemberInfo.ts @@ -35,10 +35,9 @@ export class GetMemberInfo implements IBMiComponent { } async update(connection: IBMi): Promise { - const config = connection.config!; return connection.withTempDirectory(async tempDir => { const tempSourcePath = posix.join(tempDir, `getMemberInfo.sql`); - await connection.content.writeStreamfileRaw(tempSourcePath, getSource(config.tempLibrary, this.procedureName, this.currentVersion)); + await connection.getContent().writeStreamfileRaw(tempSourcePath, getSource(connection.getConfig().tempLibrary, this.procedureName, this.currentVersion)); const result = await connection.runCommand({ command: `RUNSQLSTM SRCSTMF('${tempSourcePath}') COMMIT(*NONE) NAMING(*SQL)`, cwd: `/`, From 2b284bda44134a653698d2e7ba5ac7bcf2aee5b1 Mon Sep 17 00:00:00 2001 From: Seb Julliand Date: Fri, 27 Dec 2024 15:21:32 +0100 Subject: [PATCH 2/3] Removed GETNEWLIBL check Signed-off-by: Seb Julliand --- src/api/IBMi.ts | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/src/api/IBMi.ts b/src/api/IBMi.ts index 003fb276c..25b6c538b 100644 --- a/src/api/IBMi.ts +++ b/src/api/IBMi.ts @@ -8,7 +8,7 @@ import { IBMiComponent } from "../components/component"; import { CopyToImport } from "../components/copyToImport"; import { CustomQSh } from '../components/cqsh'; import { ComponentManager } from "../components/manager"; -import { CommandData, CommandResult, ConnectionData, IBMiMember, RemoteCommand, SpecialAuthorities, WrapResult } from "../typings"; +import { CommandData, CommandResult, ConnectionData, IBMiMember, RemoteCommand, WrapResult } from "../typings"; import { CompileTools } from "./CompileTools"; import { ConnectionConfiguration } from "./Configuration"; import IBMiContent from "./IBMiContent"; @@ -408,15 +408,6 @@ export default class IBMi { message: `Checking installed components on host IBM i.` }); - // We need to check if our remote programs are installed. - remoteApps.push( - { - path: `/QSYS.lib/${this.upperCaseName(this.config.tempLibrary)}.lib/`, - names: [`GETNEWLIBL.PGM`], - specific: `GE*.PGM` - } - ); - //Next, we see what pase features are available (installed via yum) //This may enable certain features in the future. for (const feature of remoteApps) { From abb77411f4833700bc948a4b59c35d0df098d7d2 Mon Sep 17 00:00:00 2001 From: Seb Julliand Date: Fri, 27 Dec 2024 15:21:50 +0100 Subject: [PATCH 3/3] Correctly check for getnewlibl component version Signed-off-by: Seb Julliand --- src/components/getNewLibl.ts | 62 ++++++++++++++++++++++++------------ 1 file changed, 41 insertions(+), 21 deletions(-) diff --git a/src/components/getNewLibl.ts b/src/components/getNewLibl.ts index 4082b8524..c307a8c6d 100644 --- a/src/components/getNewLibl.ts +++ b/src/components/getNewLibl.ts @@ -1,25 +1,43 @@ import { posix } from "path"; import IBMi from "../api/IBMi"; -import { instance } from "../instantiate"; import { ComponentState, IBMiComponent } from "./component"; export class GetNewLibl implements IBMiComponent { static ID = "GetNewLibl"; + private readonly procedureName = 'GETNEWLIBL'; + private readonly currentVersion = 1; + private installedVersion = 0; + + reset() { + this.installedVersion = 0; + } + getIdentification() { - return { name: GetNewLibl.ID, version: 1 }; + return { name: GetNewLibl.ID, version: this.installedVersion }; } async getRemoteState(connection: IBMi): Promise { - return connection.remoteFeatures[`GETNEWLIBL.PGM`] ? `Installed` : `NotInstalled`; + const [result] = await connection.runSQL(`select cast(LONG_COMMENT as VarChar(200)) LONG_COMMENT from qsys2.sysprocs where routine_schema = '${connection.getConfig().tempLibrary.toUpperCase()}' and routine_name = '${this.procedureName}'`); + if (result?.LONG_COMMENT) { + const comment = result.LONG_COMMENT as string; + const dash = comment.indexOf('-'); + if (dash > -1) { + this.installedVersion = Number(comment.substring(0, dash).trim()); + } + } + if (this.installedVersion < this.currentVersion) { + return `NeedsUpdate`; + } + + return `Installed`; } update(connection: IBMi): Promise { const config = connection.config! - const content = instance.getContent(); return connection.withTempDirectory(async (tempDir): Promise => { const tempSourcePath = posix.join(tempDir, `getnewlibl.sql`); - await content!.writeStreamfileRaw(tempSourcePath, getSource(config.tempLibrary)); + await connection.getContent().writeStreamfileRaw(tempSourcePath, this.getSource(config.tempLibrary)); const result = await connection.runCommand({ command: `RUNSQLSTM SRCSTMF('${tempSourcePath}') COMMIT(*NONE) NAMING(*SQL)`, cwd: `/`, @@ -36,7 +54,7 @@ export class GetNewLibl implements IBMiComponent { async getLibraryListFromCommand(connection: IBMi, ileCommand: string) { const tempLib = connection.config!.tempLibrary; - const resultSet = await connection.runSQL(`CALL ${tempLib}.GETNEWLIBL('${ileCommand.replace(new RegExp(`'`, 'g'), `''`)}')`); + const resultSet = await connection.runSQL(`CALL ${tempLib}.${this.procedureName}('${ileCommand.replace(new RegExp(`'`, 'g'), `''`)}')`); const result = { currentLibrary: `QGPL`, @@ -57,20 +75,22 @@ export class GetNewLibl implements IBMiComponent { return result; } -} -function getSource(library: string) { - return Buffer.from([ - `CREATE OR REPLACE PROCEDURE ${library}.GETNEWLIBL(IN COMMAND VARCHAR(2000))`, - `DYNAMIC RESULT SETS 1 `, - `BEGIN`, - ` DECLARE clibl CURSOR FOR `, - ` SELECT ORDINAL_POSITION, TYPE as PORTION, SYSTEM_SCHEMA_NAME`, - ` FROM QSYS2.LIBRARY_LIST_INFO;`, - ` CALL QSYS2.QCMDEXC(COMMAND);`, - ` OPEN clibl;`, - `END;`, - ``, - `call QSYS2.QCMDEXC( 'grtobjaut ${library}/GETNEWLIBL *PGM *PUBLIC *ALL' );` - ].join(`\n`), "utf8"); + private getSource(library: string) { + return Buffer.from([ + `CREATE OR REPLACE PROCEDURE ${library}.${this.procedureName}(IN COMMAND VARCHAR(2000))`, + `DYNAMIC RESULT SETS 1 `, + `BEGIN`, + ` DECLARE clibl CURSOR FOR `, + ` SELECT ORDINAL_POSITION, TYPE as PORTION, SYSTEM_SCHEMA_NAME`, + ` FROM QSYS2.LIBRARY_LIST_INFO;`, + ` CALL QSYS2.QCMDEXC(COMMAND);`, + ` OPEN clibl;`, + `END;`, + ``, + `comment on procedure ${library}.${this.procedureName} is '${this.currentVersion} - Validate member information';`, + ``, + `call QSYS2.QCMDEXC( 'grtobjaut ${library}/${this.procedureName} *PGM *PUBLIC *ALL' );` + ].join(`\n`), "utf8"); + } } \ No newline at end of file