Skip to content

Commit 672d13d

Browse files
authored
Merge pull request #2437 from codefori/fix/componentStateGetNewLibl
Correctly check GetNewLibl component state
2 parents ae2c38f + abb7741 commit 672d13d

File tree

3 files changed

+42
-32
lines changed

3 files changed

+42
-32
lines changed

src/api/IBMi.ts

Lines changed: 0 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -408,15 +408,6 @@ export default class IBMi {
408408
message: `Checking installed components on host IBM i.`
409409
});
410410

411-
// We need to check if our remote programs are installed.
412-
remoteApps.push(
413-
{
414-
path: `/QSYS.lib/${this.upperCaseName(this.config.tempLibrary)}.lib/`,
415-
names: [`GETNEWLIBL.PGM`],
416-
specific: `GE*.PGM`
417-
}
418-
);
419-
420411
//Next, we see what pase features are available (installed via yum)
421412
//This may enable certain features in the future.
422413
for (const feature of remoteApps) {

src/components/getMemberInfo.ts

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,9 @@ export class GetMemberInfo implements IBMiComponent {
3535
}
3636

3737
async update(connection: IBMi): Promise<ComponentState> {
38-
const config = connection.config!;
3938
return connection.withTempDirectory(async tempDir => {
4039
const tempSourcePath = posix.join(tempDir, `getMemberInfo.sql`);
41-
await connection.content.writeStreamfileRaw(tempSourcePath, getSource(config.tempLibrary, this.procedureName, this.currentVersion));
40+
await connection.getContent().writeStreamfileRaw(tempSourcePath, getSource(connection.getConfig().tempLibrary, this.procedureName, this.currentVersion));
4241
const result = await connection.runCommand({
4342
command: `RUNSQLSTM SRCSTMF('${tempSourcePath}') COMMIT(*NONE) NAMING(*SQL)`,
4443
cwd: `/`,

src/components/getNewLibl.ts

Lines changed: 41 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,43 @@
11
import { posix } from "path";
22
import IBMi from "../api/IBMi";
3-
import { instance } from "../instantiate";
43
import { ComponentState, IBMiComponent } from "./component";
54

65
export class GetNewLibl implements IBMiComponent {
76
static ID = "GetNewLibl";
7+
private readonly procedureName = 'GETNEWLIBL';
8+
private readonly currentVersion = 1;
9+
private installedVersion = 0;
10+
11+
reset() {
12+
this.installedVersion = 0;
13+
}
14+
815
getIdentification() {
9-
return { name: GetNewLibl.ID, version: 1 };
16+
return { name: GetNewLibl.ID, version: this.installedVersion };
1017
}
1118

1219
async getRemoteState(connection: IBMi): Promise<ComponentState> {
13-
return connection.remoteFeatures[`GETNEWLIBL.PGM`] ? `Installed` : `NotInstalled`;
20+
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}'`);
21+
if (result?.LONG_COMMENT) {
22+
const comment = result.LONG_COMMENT as string;
23+
const dash = comment.indexOf('-');
24+
if (dash > -1) {
25+
this.installedVersion = Number(comment.substring(0, dash).trim());
26+
}
27+
}
28+
if (this.installedVersion < this.currentVersion) {
29+
return `NeedsUpdate`;
30+
}
31+
32+
return `Installed`;
1433
}
1534

1635
update(connection: IBMi): Promise<ComponentState> {
1736
const config = connection.config!
18-
const content = instance.getContent();
1937
return connection.withTempDirectory(async (tempDir): Promise<ComponentState> => {
2038
const tempSourcePath = posix.join(tempDir, `getnewlibl.sql`);
2139

22-
await content!.writeStreamfileRaw(tempSourcePath, getSource(config.tempLibrary));
40+
await connection.getContent().writeStreamfileRaw(tempSourcePath, this.getSource(config.tempLibrary));
2341
const result = await connection.runCommand({
2442
command: `RUNSQLSTM SRCSTMF('${tempSourcePath}') COMMIT(*NONE) NAMING(*SQL)`,
2543
cwd: `/`,
@@ -36,7 +54,7 @@ export class GetNewLibl implements IBMiComponent {
3654

3755
async getLibraryListFromCommand(connection: IBMi, ileCommand: string) {
3856
const tempLib = connection.config!.tempLibrary;
39-
const resultSet = await connection.runSQL(`CALL ${tempLib}.GETNEWLIBL('${ileCommand.replace(new RegExp(`'`, 'g'), `''`)}')`);
57+
const resultSet = await connection.runSQL(`CALL ${tempLib}.${this.procedureName}('${ileCommand.replace(new RegExp(`'`, 'g'), `''`)}')`);
4058

4159
const result = {
4260
currentLibrary: `QGPL`,
@@ -57,20 +75,22 @@ export class GetNewLibl implements IBMiComponent {
5775

5876
return result;
5977
}
60-
}
6178

62-
function getSource(library: string) {
63-
return Buffer.from([
64-
`CREATE OR REPLACE PROCEDURE ${library}.GETNEWLIBL(IN COMMAND VARCHAR(2000))`,
65-
`DYNAMIC RESULT SETS 1 `,
66-
`BEGIN`,
67-
` DECLARE clibl CURSOR FOR `,
68-
` SELECT ORDINAL_POSITION, TYPE as PORTION, SYSTEM_SCHEMA_NAME`,
69-
` FROM QSYS2.LIBRARY_LIST_INFO;`,
70-
` CALL QSYS2.QCMDEXC(COMMAND);`,
71-
` OPEN clibl;`,
72-
`END;`,
73-
``,
74-
`call QSYS2.QCMDEXC( 'grtobjaut ${library}/GETNEWLIBL *PGM *PUBLIC *ALL' );`
75-
].join(`\n`), "utf8");
79+
private getSource(library: string) {
80+
return Buffer.from([
81+
`CREATE OR REPLACE PROCEDURE ${library}.${this.procedureName}(IN COMMAND VARCHAR(2000))`,
82+
`DYNAMIC RESULT SETS 1 `,
83+
`BEGIN`,
84+
` DECLARE clibl CURSOR FOR `,
85+
` SELECT ORDINAL_POSITION, TYPE as PORTION, SYSTEM_SCHEMA_NAME`,
86+
` FROM QSYS2.LIBRARY_LIST_INFO;`,
87+
` CALL QSYS2.QCMDEXC(COMMAND);`,
88+
` OPEN clibl;`,
89+
`END;`,
90+
``,
91+
`comment on procedure ${library}.${this.procedureName} is '${this.currentVersion} - Validate member information';`,
92+
``,
93+
`call QSYS2.QCMDEXC( 'grtobjaut ${library}/${this.procedureName} *PGM *PUBLIC *ALL' );`
94+
].join(`\n`), "utf8");
95+
}
7696
}

0 commit comments

Comments
 (0)