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/multilibfilter #2407

Merged
merged 3 commits into from
Dec 8, 2024
Merged
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
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
Loading