Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/bad_lines_from_member #2245

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions src/api/IBMi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
7 changes: 7 additions & 0 deletions src/api/Tools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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<string, number> = new Map;
/**
* Runs a function while a context value is set to true.
Expand Down
4 changes: 2 additions & 2 deletions src/filesystems/qsys/extendedContent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`
);

Expand Down
46 changes: 46 additions & 0 deletions src/testing/content.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down