@abaplint/runtime
Version:
Transpiler - Runtime
57 lines • 1.95 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.updateDatabase = updateDatabase;
const prefix_1 = require("../prefix");
const types_1 = require("../types");
const insert_database_1 = require("./insert_database");
const throw_error_1 = require("../throw_error");
async function updateDatabase(table, options, context) {
if (options.table instanceof types_1.FieldSymbol) {
options.table = options.table.getPointer();
}
if (options.from instanceof types_1.FieldSymbol) {
options.from = options.from.getPointer();
}
if (typeof table !== "string") {
table = table.get();
}
const tabl = abap.DDIC[table.toUpperCase()];
if (tabl === undefined) {
await (0, throw_error_1.throwErrorWithParameters)("CX_SY_DYNAMIC_OSQL_SEMANTICS", { sqlmsg: new types_1.String().set(`Table ${table} not found`) });
}
const keys = tabl.keyFields;
const where = [];
const set = [];
if (options.from) {
const structure = options.from.get();
for (const k of Object.keys(structure)) {
const str = k + " = " + (0, insert_database_1.toValue)(structure[k].get());
if (keys.includes(k.toUpperCase())) {
where.push(str);
}
else {
set.push(str);
}
}
}
else if (options.set) {
if (options.where) {
where.push(options.where);
}
set.push(...options.set);
}
else {
console.dir(table);
console.dir(options);
throw new Error("updateDatabase, todo");
}
const { subrc, dbcnt } = await context.defaultDB().update({
table: (0, prefix_1.buildDbTableName)(table),
where: where.join(" AND "),
set,
});
abap.builtin.sy.get().subrc.set(subrc);
abap.builtin.sy.get().dbcnt.set(dbcnt);
return subrc;
}
//# sourceMappingURL=update_database.js.map