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

Always use the copyToImport logic when running SQL. #2068

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
33 changes: 23 additions & 10 deletions src/api/CompileTools.ts
Original file line number Diff line number Diff line change
Expand Up @@ -640,16 +640,29 @@ export namespace CompileTools {
case `ile`:
default:
// escape $ and # in commands
commandResult = await connection.sendQsh({
command: [
...options.noLibList? [] : buildLiblistCommands(connection, ileSetup),
...commands.map(command =>
`${`system ${GlobalConfiguration.get(`logCompileOutput`) ? `` : `-s`} "${command.replace(/[$]/g, `\\$&`)}"`}`,
)
].join(` && `),
directory: cwd,
...callbacks
});
if (options.noLibList) {
// when we sendCommands, the encoding is entact
commandResult = await connection.sendCommand({
command: [
...commands.map(command =>
`${`system ${GlobalConfiguration.get(`logCompileOutput`) ? `` : `-s`} "${command.replace(/[$"]/g, `\\$&`)}"`}`,
)
].join(` && `),
directory: cwd,
...callbacks
});
} else {
commandResult = await connection.sendQsh({
command: [
buildLiblistCommands(connection, ileSetup),
...commands.map(command =>
`${`system ${GlobalConfiguration.get(`logCompileOutput`) ? `` : `-s`} "${command.replace(/[$"]/g, `\\$&`)}"`}`,
)
].join(` && `),
directory: cwd,
...callbacks
});
}
break;
}

Expand Down
35 changes: 19 additions & 16 deletions src/api/IBMi.ts
Original file line number Diff line number Diff line change
Expand Up @@ -620,6 +620,7 @@ export default class IBMi {

// Fetch conversion values?
if (quickConnect === true && cachedServerSettings?.jobCcsid !== null && cachedServerSettings?.variantChars && cachedServerSettings?.userDefaultCCSID && cachedServerSettings?.qccsid) {
this.qccsid = cachedServerSettings.qccsid;
this.jobCcsid = cachedServerSettings.jobCcsid;
this.variantChars = cachedServerSettings.variantChars;
this.userDefaultCCSID = cachedServerSettings.userDefaultCCSID;
Expand Down Expand Up @@ -1273,6 +1274,10 @@ export default class IBMi {
* @param name
*/
upperCaseName(name: string) {
if (name.startsWith(`"`) && name.endsWith(`"`)) {
return name;
}

if (this.dangerousVariants && new RegExp(`[${this.variantChars.local}]`).test(name)) {
const upperCased = [];
for (const char of name) {
Expand Down Expand Up @@ -1315,24 +1320,22 @@ export default class IBMi {

let returningAsCsv: WrapResult | undefined;

if (this.qccsid === 65535) {
let list = input.split(`\n`).join(` `).split(`;`).filter(x => x.trim().length > 0);
const lastStmt = list.pop()?.trim();
const asUpper = lastStmt?.toUpperCase();

if (lastStmt) {
if ((asUpper?.startsWith(`SELECT`) || asUpper?.startsWith(`WITH`))) {
const copyToImport = this.getComponent<CopyToImport>(`CopyToImport`);
if (copyToImport) {
returningAsCsv = copyToImport.wrap(lastStmt);
list.push(...returningAsCsv.newStatements);
input = list.join(`;\n`);
}
let list = input.split(`\n`).join(` `).split(`;`).filter(x => x.trim().length > 0);
const lastStmt = list.pop()?.trim();
const asUpper = lastStmt?.toUpperCase();

if (lastStmt) {
if ((asUpper?.startsWith(`SELECT`) || asUpper?.startsWith(`WITH`))) {
const copyToImport = this.getComponent<CopyToImport>(`CopyToImport`);
if (copyToImport) {
returningAsCsv = copyToImport.wrap(lastStmt);
list.push(...returningAsCsv.newStatements);
input = list.join(`;\n`);
}
}

if (!returningAsCsv) {
list.push(lastStmt);
}
if (!returningAsCsv) {
list.push(lastStmt);
}
}

Expand Down
2 changes: 1 addition & 1 deletion src/api/IBMiContent.ts
Original file line number Diff line number Diff line change
Expand Up @@ -505,7 +505,7 @@ export default class IBMiContent {
` extract(epoch from (CHANGE_TIMESTAMP))*1000 as CHANGED,`,
` OBJOWNER as OWNER,`,
` OBJDEFINER as CREATED_BY`,
`from table(QSYS2.OBJECT_STATISTICS(OBJECT_SCHEMA => '${library.padEnd(10)}', OBJTYPELIST => '${type}'${objectName()}))`,
`from table(QSYS2.OBJECT_STATISTICS(OBJECT_SCHEMA => '${library}', OBJTYPELIST => '${type}'${objectName()}))`,
];
}
else {
Expand Down
59 changes: 59 additions & 0 deletions src/testing/globalization.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
import assert from "assert";
import { TestSuite } from ".";
import { instance } from "../instantiate";

const testData = {
'273': {
library: '"Aܧ#$%Ä"',
libraryText: '"§#$öße"',
object: '"àáãÄ£ø"',
objectText: '"Üä$öß"',
member: '"§#$MAN"',
memberText: '"§#$öße"',
memberType: 'CBLLE'
}
}

export const GlobalizationSuite: TestSuite = {
name: `Globalization tests`,

tests: Object.keys(testData).map(ccsid => {
return {
name: `CCSID ${ccsid}`, test: async () => {
const connection = instance.getConnection();
const content = instance.getContent();

const test = testData[ccsid as keyof typeof testData];

// Temporarily update user profile default CCSID
const [originalUserDefaultCCSID] = await content!.ibmi.runSQL(`select CHARACTER_CODE_SET_ID from table( QSYS2.QSYUSRINFO( USERNAME => upper('${content!.ibmi.currentUser}') ) )`);
const newCssidRes = await connection!.runCommand({ command: `CHGUSRPRF USRPRF(${content!.ibmi.currentUser}) CCSID(${ccsid})`, noLibList: true });
SanjulaGanepola marked this conversation as resolved.
Show resolved Hide resolved
const [newUserDefaultCCSID] = await content!.ibmi.runSQL(`select CHARACTER_CODE_SET_ID from table( QSYS2.QSYUSRINFO( USERNAME => upper('${content!.ibmi.currentUser}') ) )`);
assert.strictEqual(newUserDefaultCCSID.CHARACTER_CODE_SET_ID, Number(ccsid));

const crtlibRes = await connection!.runCommand({ command: `CRTLIB LIB(${test.library}) TEXT(${test.libraryText})`, noLibList: true, environment: "ile" });
const crtsrcpfRes = await connection!.runCommand({ command: `CRTSRCPF FILE(${test.library}/${test.object}) RCDLEN(112) CCSID(${ccsid}) TEXT(${test.objectText})`, noLibList: true, environment: "ile" });
const addpfmRes = await connection!.runCommand({ command: `ADDPFM FILE(${test.library}/${test.object}) MBR(${test.member}) SRCTYPE(${test.memberType}) TEXT(${test.memberText})`, noLibList: true, environment: "ile" });
const libraries = await content!.getObjectList({ library: test.library, types: ['*LIB']});
const objects = await content!.getObjectList({ library: test.library, object: test.object });
const members = await content!.getMemberList({ library: test.library, sourceFile: test.object, members: test.member });
const dltLib = await connection!.runCommand({ command: `DLTLIB LIB(${test.library})`, noLibList: true, environment: "ile" });

// Restore user profile default CCSID
const restoreCcsidRes = await connection!.runCommand({ command: `CHGUSRPRF USRPRF(${content!.ibmi.currentUser}) CCSID(${originalUserDefaultCCSID.CHARACTER_CODE_SET_ID})`, noLibList: true });
const [restoredUserDefaultCCSID] = await content!.ibmi.runSQL(`select CHARACTER_CODE_SET_ID from table( QSYS2.QSYUSRINFO( USERNAME => upper('${content!.ibmi.currentUser}') ) )`);
assert.strictEqual(restoredUserDefaultCCSID.CHARACTER_CODE_SET_ID, originalUserDefaultCCSID.CHARACTER_CODE_SET_ID);

assert.strictEqual(libraries.length, 1);
assert.strictEqual(libraries[0].library, test.library);
assert.strictEqual(libraries[0].text, test.libraryText);
assert.strictEqual(objects.length, 1);
assert.strictEqual(objects[0].name, test.object);
assert.strictEqual(objects[0].text, test.objectText);
assert.strictEqual(members.length, 1);
assert.strictEqual(members[0].name, test.member);
assert.strictEqual(members[0].text, test.memberText);
}
}
})
};
2 changes: 2 additions & 0 deletions src/testing/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { ILEErrorSuite } from "./ileErrors";
import { StorageSuite } from "./storage";
import { TestSuitesTreeProvider } from "./testCasesTree";
import { ToolsSuite } from "./tools";
import { GlobalizationSuite } from "./globalization";

const suites: TestSuite[] = [
ActionSuite,
Expand All @@ -23,6 +24,7 @@ const suites: TestSuite[] = [
FilterSuite,
StorageSuite,
EncodingSuite,
GlobalizationSuite,
ComponentSuite
]

Expand Down