Skip to content

Commit

Permalink
Merge pull request #2007 from codefori/fix/handle_empty_columns
Browse files Browse the repository at this point in the history
Fix issue where empty columns were returning as zero.
  • Loading branch information
worksofliam authored Apr 25, 2024
2 parents 3f65f3f + 5fa2fa1 commit e294fa4
Show file tree
Hide file tree
Showing 2 changed files with 47 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/api/Tools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -133,12 +133,12 @@ export namespace Tools {
let realValue: string | number | null = strValue.trimEnd();

// is value a number?
if (strValue.startsWith(` `)) {
if (realValue.startsWith(` `)) {
const asNumber = Number(strValue.trim());
if (!isNaN(asNumber)) {
realValue = asNumber;
}
} else if (strValue === `-`) {
} else if (realValue === `-`) {
realValue = null; //null?
}

Expand Down Expand Up @@ -361,21 +361,21 @@ export namespace Tools {
await vscode.commands.executeCommand(`setContext`, context, true);
activeContexts.set(context, 0);
}
else{
else {
activeContexts.set(context, stack++);
}
return await task();
}
finally {
let stack = activeContexts.get(context);
if (stack !== undefined) {
if(stack){
if (stack) {
activeContexts.set(context, stack--);
}
else{
else {
await vscode.commands.executeCommand(`setContext`, context, undefined);
activeContexts.delete(context);
}
}
}
}
}
Expand Down
41 changes: 41 additions & 0 deletions src/testing/tools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,47 @@ export const ToolsSuite: TestSuite = {
assert.strictEqual(rows[0].CDTDUE, 0);
}
},
{
name: `EN result set, empty columns`, test: async () => {
const lines = [
`DB2>`,
`DB20000I THE SQL COMMAND COMPLETED SUCCESSFULLY.`,
`DB2>`,
`DB20000I THE SQL COMMAND COMPLETED SUCCESSFULLY.`,
`DB2>`,
``,
`NAME TYPE ATTRIBUTE TEXT IS_SOURCE NB_MBR SOURCE_LENGTH CCSID `,
`---------- ----- ---------- -------------------------------------------------- ----------- ------- -------------- -------`,
`CMD *FILE *PHY 1 3 112 37 `,
`EVFTEMPF01 *FILE *PHY 1 2 112 37 `,
`EVFTEMPF02 *FILE *PHY 1 2 112 37 `,
`HEBREW *FILE *PHY 1 1 92 424 `,
`QCPYSRC *FILE *PHY 1 1 112 37 `,
`QDDSSRC *FILE *PHY 1 3 112 37 `,
`QRPGLEREF *FILE *PHY 1 1 112 37 `,
`QRPGLESRC *FILE *PHY cool mate 1 11 112 37 `,
`QSQDSRC *FILE *PHY SQL PROCEDURES 1 4 160 37 `,
`VSCODE *FILE *PHY 1 1 112 37 `,
``,
` 10 RECORD(S) SELECTED.`,
``,
`DB2>`,
]

const rows = Tools.db2Parse(lines.join(`\n`));

assert.strictEqual(rows.length, 10);

assert.strictEqual(rows[0].NAME, `CMD`);
assert.strictEqual(rows[0].TYPE, `*FILE`);
assert.strictEqual(rows[0].ATTRIBUTE, `*PHY`);
assert.strictEqual(rows[0].TEXT, ``);
assert.strictEqual(rows[0].IS_SOURCE, 1);
assert.strictEqual(rows[0].NB_MBR, 3);
assert.strictEqual(rows[0].SOURCE_LENGTH, 112);
assert.strictEqual(rows[0].CCSID, 37);
}
},
{
name: `FR result set test`, test: async () => {
const lines = [
Expand Down

0 comments on commit e294fa4

Please sign in to comment.