From 3d4a6115564a55166b7b211a596bec6ed62a87f7 Mon Sep 17 00:00:00 2001 From: worksofliam Date: Mon, 2 Sep 2024 21:33:16 -0400 Subject: [PATCH 1/3] Implement custom casting function Signed-off-by: worksofliam --- src/api/IBMi.ts | 3 +-- src/api/Tools.ts | 7 +++++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/src/api/IBMi.ts b/src/api/IBMi.ts index fe2efe28b..fca706830 100644 --- a/src/api/IBMi.ts +++ b/src/api/IBMi.ts @@ -1416,10 +1416,9 @@ export default class IBMi { return parse(csvContent, { columns: true, skip_empty_lines: true, - cast: true, onRecord(record) { for (const key of Object.keys(record)) { - record[key] = record[key] === ` ` ? `` : record[key]; + record[key] = record[key] === ` ` ? `` : Tools.assumeType(record[key]); } return record; } diff --git a/src/api/Tools.ts b/src/api/Tools.ts index 38433c105..27b4d0ef0 100644 --- a/src/api/Tools.ts +++ b/src/api/Tools.ts @@ -390,6 +390,13 @@ export namespace Tools { } } + export function assumeType(str: string) { + // The number is already generated on the server. + // So, we assume that if the string starts with a 0, it is a string. + if (str[0] === `0` || str.length > 10) return str; + return Number(str) || str; + } + const activeContexts: Map = new Map; /** * Runs a function while a context value is set to true. From 00482be4e9d85dc20a480650ad954711af45f2d6 Mon Sep 17 00:00:00 2001 From: worksofliam Date: Mon, 2 Sep 2024 21:33:36 -0400 Subject: [PATCH 2/3] Remove use of deprecated function Signed-off-by: worksofliam --- src/filesystems/qsys/extendedContent.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/filesystems/qsys/extendedContent.ts b/src/filesystems/qsys/extendedContent.ts index 477bd3154..85928f2a3 100644 --- a/src/filesystems/qsys/extendedContent.ts +++ b/src/filesystems/qsys/extendedContent.ts @@ -52,11 +52,11 @@ export class ExtendedIBMiContent { let rows; if (sourceColourSupport) - rows = await content.runSQL( + rows = await connection.runSQL( `select srcdat, rtrim(translate(srcdta, ${SEU_GREEN_UL_RI_temp}, ${SEU_GREEN_UL_RI})) as srcdta from ${aliasPath}` ); else - rows = await content.runSQL( + rows = await connection.runSQL( `select srcdat, srcdta from ${aliasPath}` ); From 178c3912c703265301a30a2a50e5db312797973f Mon Sep 17 00:00:00 2001 From: worksofliam Date: Mon, 2 Sep 2024 21:34:31 -0400 Subject: [PATCH 3/3] Implement test for ensuring correct lines are returned Signed-off-by: worksofliam --- src/testing/content.ts | 46 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) diff --git a/src/testing/content.ts b/src/testing/content.ts index a99b78ae3..9074f43ce 100644 --- a/src/testing/content.ts +++ b/src/testing/content.ts @@ -278,6 +278,52 @@ export const ContentSuite: TestSuite = { }, }, + {name: `Ensure source lines are correct`, test: async () => { + const connection = instance.getConnection(); + const config = instance.getConfig()!; + + assert.ok(config.enableSourceDates, `Source dates must be enabled for this test.`); + + const tempLib = config!.tempLibrary; + const file = `LINES`; + const member = `THEMEMBER`; + + await connection!.runCommand({ command: `CRTSRCPF FILE(${tempLib}/${file}) RCDLEN(112)`, noLibList: true }); + await connection!.runCommand({ command: `ADDPFM FILE(${tempLib}/${file}) MBR(${member}) SRCTYPE(TXT)`, noLibList: true }); + + const aliasName = `${tempLib}.test_${file}_${member}`; + await connection?.runSQL(`CREATE OR REPLACE ALIAS ${aliasName} for "${tempLib}"."${file}"("${member}")`); + + try { + await connection?.runSQL(`delete from ${aliasName}`); + } catch (e) {} + + const inLines = [ + `Hello world`, + `1`, + `001`, + `0002`, + `00003`, + ] + + const lines = [ + `insert into ${aliasName} (srcseq, srcdat, srcdta)`, + `values `, + inLines.map((line, index) => `(${index + 1}.00, 0, '${line}')`).join(`, `), + ]; + + await connection?.runSQL(lines.join(` `)); + + const theBadOneUri = getMemberUri({ library: tempLib, file, name: member, extension: `TXT` }); + + const memberContentBuf = await workspace.fs.readFile(theBadOneUri); + const fileContent = new TextDecoder().decode(memberContentBuf); + + const outLines = fileContent.split(`\n`); + + assert.deepStrictEqual(inLines, outLines); + }}, + { name: `Test runSQL (basic select)`, test: async () => { const content = instance.getContent();