@abaplint/runtime
Version:
Transpiler - Runtime
31 lines • 1.25 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 = [];
for (const row of table.array()) {
if (row.get().sign?.get() === "I" && row.get().option?.get() === "EQ") {
values.push(`"${fieldName}" = '` + row.get().low?.get().replace(/'/g, "''") + "'");
}
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