Skip to content

Commit f3ad5e7

Browse files
authored
Merge pull request #339 from codefori/fix/library_name_not_supplied
Fix for SQL syntax checker crash due to invalid statement
2 parents 74c5514 + bd22cb7 commit f3ad5e7

File tree

3 files changed

+41
-20
lines changed

3 files changed

+41
-20
lines changed

.github/workflows/release.yaml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ jobs:
1414
node-version: '20'
1515
- uses: actions/checkout@v2
1616

17-
- run: npm install
17+
- run: npm ci
1818

1919
- run: npm install -g vsce ovsx
2020

.github/workflows/webpack_ci.yaml

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,6 @@
11
name: NodeJS with Webpack
22

3-
on:
4-
push:
5-
branches: [ "main" ]
6-
pull_request:
7-
branches: [ "main" ]
3+
on: pull_request
84

95
jobs:
106
build:
@@ -22,9 +18,14 @@ jobs:
2218
with:
2319
node-version: ${{ matrix.node-version }}
2420

21+
- name: Install dependencies
22+
run: npm ci
23+
24+
- name: Type check
25+
run: npm run typings
26+
2527
- name: Build and package
2628
run: |
27-
npm install
2829
npx webpack
2930
npm install -g vsce
3031
vsce package
@@ -49,6 +50,7 @@ jobs:
4950
body-includes: new build is available
5051

5152
- name: Post comment
53+
continue-on-error: true
5254
if: steps.fc.outputs.comment-id == ''
5355
uses: actions/github-script@v5
5456
with:
@@ -61,6 +63,7 @@ jobs:
6163
})
6264
6365
- name: Update comment
66+
continue-on-error: true
6467
if: steps.fc.outputs.comment-id != ''
6568
uses: peter-evans/create-or-update-comment@v1
6669
with:

src/connection/syntaxChecker/index.ts

Lines changed: 31 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ import { ComponentIdentification, ComponentState, IBMiComponent } from "@halcyon
33
import { posix } from "path";
44
import { getValidatorSource, VALIDATOR_NAME, WRAPPER_NAME } from "./checker";
55
import { JobManager } from "../../config";
6-
import { getInstance } from "../../base";
6+
import { getBase, getInstance } from "../../base";
77

88
interface SqlCheckError {
99
CURSTMTLENGTH: number;
@@ -42,14 +42,23 @@ export class SQLStatementChecker implements IBMiComponent {
4242
private readonly functionName = VALIDATOR_NAME;
4343
private readonly currentVersion = 5;
4444

45-
private library = "";
45+
private library: string|undefined;
46+
47+
private getLibrary(connection: IBMi) {
48+
if (!this.library) {
49+
this.library = connection?.config?.tempLibrary.toUpperCase() || `ILEDITOR`;
50+
}
51+
52+
return this.library;
53+
}
4654

4755
static get(): SQLStatementChecker|undefined {
4856
return getInstance()?.getConnection()?.getComponent<SQLStatementChecker>(SQLStatementChecker.ID);
4957
}
5058

5159
reset() {
52-
this.library = "";
60+
// This is called when connecting to a new system.
61+
this.library = undefined;
5362
}
5463

5564
getIdentification(): ComponentIdentification {
@@ -70,14 +79,14 @@ export class SQLStatementChecker implements IBMiComponent {
7079
}
7180

7281
async getRemoteState(connection: IBMi) {
73-
this.library = connection.config?.tempLibrary.toUpperCase() || "ILEDITOR";
82+
const lib = this.getLibrary(connection);
7483

75-
const wrapperVersion = await SQLStatementChecker.getVersionOf(connection, this.library, WRAPPER_NAME);
84+
const wrapperVersion = await SQLStatementChecker.getVersionOf(connection, lib, WRAPPER_NAME);
7685
if (wrapperVersion < this.currentVersion) {
7786
return `NeedsUpdate`;
7887
}
7988

80-
const installedVersion = await SQLStatementChecker.getVersionOf(connection, this.library, this.functionName);
89+
const installedVersion = await SQLStatementChecker.getVersionOf(connection, lib, this.functionName);
8190
if (installedVersion < this.currentVersion) {
8291
return `NeedsUpdate`;
8392
}
@@ -88,7 +97,7 @@ export class SQLStatementChecker implements IBMiComponent {
8897
update(connection: IBMi): ComponentState | Promise<ComponentState> {
8998
return connection.withTempDirectory(async tempDir => {
9099
const tempSourcePath = posix.join(tempDir, `sqlchecker.sql`);
91-
await connection.content.writeStreamfileRaw(tempSourcePath, Buffer.from(this.getSource(), "utf-8"));
100+
await connection.content.writeStreamfileRaw(tempSourcePath, Buffer.from(this.getSource(connection), "utf-8"));
92101
const result = await connection.runCommand({
93102
command: `RUNSQLSTM SRCSTMF('${tempSourcePath}') COMMIT(*NONE) NAMING(*SYS)`,
94103
noLibList: true
@@ -102,14 +111,19 @@ export class SQLStatementChecker implements IBMiComponent {
102111
});
103112
}
104113

105-
private getSource() {
106-
return getValidatorSource(this.library, this.currentVersion);
114+
private getSource(connection: IBMi) {
115+
return getValidatorSource(this.getLibrary(connection), this.currentVersion);
107116
}
108117

109118
async call(statement: string): Promise<SqlSyntaxError|undefined> {
119+
const connection = getInstance()?.getConnection();
120+
if (!connection) return undefined;
121+
110122
const currentJob = JobManager.getSelection();
111-
if (currentJob) {
112-
const result = await currentJob.job.execute<SqlCheckError>(`select * from table(${this.library}.${this.functionName}(?)) x`, {parameters: [statement]});
123+
const library = this.getLibrary(connection);
124+
125+
if (currentJob && library) {
126+
const result = await currentJob.job.execute<SqlCheckError>(`select * from table(${library}.${this.functionName}(?)) x`, {parameters: [statement]});
113127

114128
if (!result.success || result.data.length === 0) return;
115129

@@ -121,10 +135,14 @@ export class SQLStatementChecker implements IBMiComponent {
121135
}
122136

123137
async checkMultipleStatements(statements: string[]): Promise<SqlSyntaxError[]|undefined> {
124-
const checks = statements.map(stmt => `select * from table(${this.library}.${this.functionName}(?)) x`).join(` union all `);
138+
const connection = getInstance()?.getConnection();
139+
if (!connection) return undefined;
140+
125141
const currentJob = JobManager.getSelection();
142+
const library = this.getLibrary(connection);
126143

127-
if (currentJob) {
144+
if (currentJob && library) {
145+
const checks = statements.map(stmt => `select * from table(${library}.${this.functionName}(?)) x`).join(` union all `);
128146
const stmt = currentJob.job.query<SqlCheckError>(checks, {parameters: statements});
129147
const result = await stmt.execute(statements.length);
130148
stmt.close();

0 commit comments

Comments
 (0)