@abaplint/runtime
Version:
Transpiler - Runtime
42 lines • 1.81 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.expandIN = expandIN;
// note: must always return an expression, never return empty string
// https://www.sqlite.org/lang_select.html
function expandIN(fieldName, table) {
let ret = "";
if (table.array().length === 0) {
// " NOT IN ()" does not work on postgres
// LIKE '%' does not work in snowflake with RTRIM collation
ret = `true`;
}
else {
ret = `(`;
const values = [];
fieldName = fieldName.replace("~", `"."`);
for (const row of table.array()) {
const val = `'` + row.get().low?.get().replace(/'/g, "''") + "'";
if (row.get().sign?.get() === "I" && row.get().option?.get() === "EQ") {
values.push(`"${fieldName}" = ` + val);
}
else if (row.get().sign?.get() === "I" && row.get().option?.get() === "NE") {
values.push(`"${fieldName}" <> ` + val);
}
else if (row.get().sign?.get() === "I" && row.get().option?.get() === "GE") {
values.push(`"${fieldName}" >= ` + val);
}
else if (row.get().sign?.get() === "I" && row.get().option?.get() === "LE") {
values.push(`"${fieldName}" <= ` + val);
}
else if (row.get().sign?.get() === "I" && row.get().option?.get() === "CP") {
values.push(`"${fieldName}" LIKE '` + row.get().low?.get().trimEnd().replace(/'/g, "''").replace(/\*/g, "%") + "'");
}
else {
throw new Error(`IN, ${row.get().sign?.get()} ${row.get().option?.get()} not supported`);
}
}
ret += values.join(" OR ") + ")";
}
return ret;
}
//# sourceMappingURL=expand_in.js.map