Skip to content

Commit

Permalink
Merge pull request #2407 from codefori/fix/multilibfilter
Browse files Browse the repository at this point in the history
Fix/multilibfilter
  • Loading branch information
worksofliam authored Dec 8, 2024
2 parents a4d7630 + 4e568b0 commit e2074b0
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 42 deletions.
16 changes: 11 additions & 5 deletions src/api/IBMiContent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -473,7 +473,13 @@ export default class IBMiContent {
}

async getLibraries(filters: { library: string; filterType?: FilterType }) {
return this.getObjectList({ library: "QSYS", object: filters.library, types: ["*LIB"], filterType: filters.filterType });
const libraries: IBMiObject[] = [];
for (const library of filters.library.split(",")) {
(await this.getObjectList({ library: "QSYS", object: library.trim(), types: ["*LIB"], filterType: filters.filterType }))
.filter(lib => !libraries.find(l => l.name === lib.name))
.forEach(lib => libraries.push(lib));
}
return libraries;
}

/**
Expand Down Expand Up @@ -942,7 +948,7 @@ export default class IBMiContent {
}

async getAttributes(path: string | (QsysPath & { member?: string }), ...operands: AttrOperands[]) {
const localPath = typeof path === `string` ? path : {...path};
const localPath = typeof path === `string` ? path : { ...path };
const assumeMember = typeof localPath === `object`;
let target: string;

Expand All @@ -961,11 +967,11 @@ export default class IBMiContent {

if (assumeMember) {
target = IBMi.escapeForShell(target);
result = await this.ibmi.sendQsh({ command: `${this.ibmi.remoteFeatures.attr} -p ${target} ${operands.join(" ")}`});
result = await this.ibmi.sendQsh({ command: `${this.ibmi.remoteFeatures.attr} -p ${target} ${operands.join(" ")}` });
} else {
target = Tools.escapePath(target, true);
// Take {DOES_THIS_WORK: `YESITDOES`} away, and all of a sudden names with # aren't found.
result = await this.ibmi.sendCommand({ command: `${this.ibmi.remoteFeatures.attr} -p "${target}" ${operands.join(" ")}`, env: {DOES_THIS_WORK: `YESITDOES`}});
result = await this.ibmi.sendCommand({ command: `${this.ibmi.remoteFeatures.attr} -p "${target}" ${operands.join(" ")}`, env: { DOES_THIS_WORK: `YESITDOES` } });
}

if (result.code === 0) {
Expand Down Expand Up @@ -1050,7 +1056,7 @@ export default class IBMiContent {
}
}

function safeIsoValue(date: Date|undefined) {
function safeIsoValue(date: Date | undefined) {
try {
return date ? date.toISOString().slice(0, 19).replace(`T`, ` `) : ``;
} catch (e) {
Expand Down
81 changes: 44 additions & 37 deletions src/testing/content.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { TestSuite } from ".";
import { Tools } from "../api/Tools";
import { getMemberUri } from "../filesystems/qsys/QSysFs";
import { instance } from "../instantiate";
import { CommandResult, IBMiObject } from "../typings";
import { CommandResult } from "../typings";

export const ContentSuite: TestSuite = {
name: `Content API tests`,
Expand Down Expand Up @@ -249,51 +249,53 @@ export const ContentSuite: TestSuite = {
}
},

{name: `Ensure source lines are correct`, test: async () => {
const connection = instance.getConnection();
const config = instance.getConfig()!;
{
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.`);
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 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}")`);
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) {}
try {
await connection?.runSQL(`delete from ${aliasName}`);
} catch (e) { }

const inLines = [
`Hello world`,
`1`,
`001`,
`0002`,
`00003`,
]
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(`, `),
];
const lines = [
`insert into ${aliasName} (srcseq, srcdat, srcdta)`,
`values `,
inLines.map((line, index) => `(${index + 1}.00, 0, '${line}')`).join(`, `),
];

await connection?.runSQL(lines.join(` `));
await connection?.runSQL(lines.join(` `));

const theBadOneUri = getMemberUri({ library: tempLib, file, name: member, extension: `TXT` });
const theBadOneUri = getMemberUri({ library: tempLib, file, name: member, extension: `TXT` });

const memberContentBuf = await workspace.fs.readFile(theBadOneUri);
const fileContent = new TextDecoder().decode(memberContentBuf);
const memberContentBuf = await workspace.fs.readFile(theBadOneUri);
const fileContent = new TextDecoder().decode(memberContentBuf);

const outLines = fileContent.split(`\n`);
const outLines = fileContent.split(`\n`);

assert.deepStrictEqual(inLines, outLines);
}},
assert.deepStrictEqual(inLines, outLines);
}
},

{
name: `Test runSQL (basic select)`, test: async () => {
Expand Down Expand Up @@ -486,6 +488,11 @@ export const ContentSuite: TestSuite = {
const includeSYSLibraries = await content?.getLibraries({ library: "*SYS*" });
assert.notStrictEqual(includeSYSLibraries?.length, 0);
assert.strictEqual(includeSYSLibraries?.every(l => l.name.includes("SYS")), true);

const libraries = ["QSYSINC", "QGPL", "QTEMP"];
const multipleLibraries = await content?.getLibraries({ library: libraries.join(",") })
assert.strictEqual(multipleLibraries?.length, libraries.length);
assert.strictEqual(libraries.every(l => multipleLibraries.some(o => o.name === l)), true);
}
},
{
Expand Down Expand Up @@ -631,10 +638,10 @@ export const ContentSuite: TestSuite = {
assert.strictEqual(memberInfoB?.extension === `CPP`, true);
assert.strictEqual(memberInfoB?.text === `C++ HEADER`, true);

try{
try {
await content?.getMemberInfo(`QSYSINC`, `H`, `OH_NONO`)
}
catch(error: any){
catch (error: any) {
assert.ok(error instanceof Tools.SqlError);
assert.strictEqual(error.sqlstate, "38501");
}
Expand Down

0 comments on commit e2074b0

Please sign in to comment.