@abaplint/runtime 2.7.95 → 2.7.97

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,8 +1,12 @@
1
1
  import { Console } from "./console/console";
2
- import { DatabaseClient } from "./db/db";
2
+ import { DatabaseClient, DatabaseCursorCallbacks } from "./db/db";
3
3
  import * as RFC from "./rfc";
4
4
  export declare class Context {
5
5
  console: Console;
6
+ cursorCounter: number;
7
+ cursors: {
8
+ [key: number]: DatabaseCursorCallbacks;
9
+ };
6
10
  databaseConnections: {
7
11
  [name: string]: DatabaseClient;
8
12
  };
@@ -3,6 +3,8 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Context = void 0;
4
4
  class Context {
5
5
  constructor() {
6
+ this.cursorCounter = 0;
7
+ this.cursors = {};
6
8
  // DEFAULT and secondary database connections
7
9
  this.databaseConnections = {};
8
10
  this.RFCDestinations = {};
@@ -29,6 +29,10 @@ export type DatabaseRows = DatabaseRow[];
29
29
  export interface SelectDatabaseResult {
30
30
  rows: DatabaseRows;
31
31
  }
32
+ export type DatabaseCursorCallbacks = {
33
+ fetchNextCursor: (packageSize: number) => Promise<SelectDatabaseResult>;
34
+ closeCursor: () => Promise<void>;
35
+ };
32
36
  export interface DatabaseClient {
33
37
  /*** the type/name/identifier of the database */
34
38
  name: string;
@@ -52,4 +56,5 @@ export interface DatabaseClient {
52
56
  dbcnt: number;
53
57
  }>;
54
58
  select(options: SelectDatabaseOptions): Promise<SelectDatabaseResult>;
59
+ openCursor(options: SelectDatabaseOptions): Promise<DatabaseCursorCallbacks>;
55
60
  }
@@ -0,0 +1,2 @@
1
+ import { Context } from "../context";
2
+ export declare function closeCursor(context: Context, cursor: number): Promise<void>;
@@ -0,0 +1,9 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.closeCursor = void 0;
4
+ async function closeCursor(context, cursor) {
5
+ await context.cursors[cursor].closeCursor();
6
+ delete context.cursors[cursor];
7
+ }
8
+ exports.closeCursor = closeCursor;
9
+ //# sourceMappingURL=close_cursor.js.map
@@ -6,8 +6,4 @@ export interface IDeleteDatabaseOptions {
6
6
  where?: string;
7
7
  table?: Table | FieldSymbol;
8
8
  }
9
- export declare class DeleteDatabase {
10
- private readonly context;
11
- constructor(context: Context);
12
- deleteDatabase(table: string | ICharacter, options: IDeleteDatabaseOptions): Promise<void>;
13
- }
9
+ export declare function deleteDatabase(table: string | ICharacter, options: IDeleteDatabaseOptions, context: Context): Promise<void>;
@@ -1,59 +1,54 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.DeleteDatabase = void 0;
3
+ exports.deleteDatabase = void 0;
4
4
  const prefix_1 = require("../prefix");
5
5
  const types_1 = require("../types");
6
6
  const insert_database_1 = require("./insert_database");
7
- class DeleteDatabase {
8
- constructor(context) {
9
- this.context = context;
7
+ async function deleteDatabase(table, options, context) {
8
+ if (options.table instanceof types_1.FieldSymbol) {
9
+ options.table = options.table.getPointer();
10
10
  }
11
- async deleteDatabase(table, options) {
12
- if (options.table instanceof types_1.FieldSymbol) {
13
- options.table = options.table.getPointer();
14
- }
15
- if (options.from instanceof types_1.FieldSymbol) {
16
- options.from = options.from.getPointer();
17
- }
18
- if (typeof table !== "string") {
19
- table = table.get().trimEnd();
20
- }
21
- if (options.table) {
22
- for (const row of options.table.array()) {
23
- await this.deleteDatabase(table, { from: row });
24
- }
25
- }
26
- else if (options.from) {
27
- let where = [];
28
- const structure = options.from.get();
29
- for (const k of Object.keys(structure)) {
30
- const str = `"${k.toLowerCase()}"` + " = " + (0, insert_database_1.toValue)(structure[k].get());
31
- where.push(str);
32
- }
33
- where = where.join(" AND ");
34
- const { subrc, dbcnt } = await this.context.defaultDB().delete({
35
- table: (0, prefix_1.buildDbTableName)(table),
36
- where,
37
- });
38
- // @ts-ignore
39
- abap.builtin.sy.get().subrc.set(subrc);
40
- // @ts-ignore
41
- abap.builtin.sy.get().dbcnt.set(dbcnt);
42
- }
43
- else if (options.where) {
44
- const { subrc, dbcnt } = await this.context.defaultDB().delete({
45
- table: (0, prefix_1.buildDbTableName)(table),
46
- where: options.where,
47
- });
48
- // @ts-ignore
49
- abap.builtin.sy.get().subrc.set(subrc);
50
- // @ts-ignore
51
- abap.builtin.sy.get().dbcnt.set(dbcnt);
11
+ if (options.from instanceof types_1.FieldSymbol) {
12
+ options.from = options.from.getPointer();
13
+ }
14
+ if (typeof table !== "string") {
15
+ table = table.get().trimEnd();
16
+ }
17
+ if (options.table) {
18
+ for (const row of options.table.array()) {
19
+ await deleteDatabase(table, { from: row }, context);
52
20
  }
53
- else {
54
- throw "deleteDatabase todo";
21
+ }
22
+ else if (options.from) {
23
+ let where = [];
24
+ const structure = options.from.get();
25
+ for (const k of Object.keys(structure)) {
26
+ const str = `"${k.toLowerCase()}"` + " = " + (0, insert_database_1.toValue)(structure[k].get());
27
+ where.push(str);
55
28
  }
29
+ where = where.join(" AND ");
30
+ const { subrc, dbcnt } = await context.defaultDB().delete({
31
+ table: (0, prefix_1.buildDbTableName)(table),
32
+ where,
33
+ });
34
+ // @ts-ignore
35
+ abap.builtin.sy.get().subrc.set(subrc);
36
+ // @ts-ignore
37
+ abap.builtin.sy.get().dbcnt.set(dbcnt);
38
+ }
39
+ else if (options.where) {
40
+ const { subrc, dbcnt } = await context.defaultDB().delete({
41
+ table: (0, prefix_1.buildDbTableName)(table),
42
+ where: options.where,
43
+ });
44
+ // @ts-ignore
45
+ abap.builtin.sy.get().subrc.set(subrc);
46
+ // @ts-ignore
47
+ abap.builtin.sy.get().dbcnt.set(dbcnt);
48
+ }
49
+ else {
50
+ throw "deleteDatabase todo";
56
51
  }
57
52
  }
58
- exports.DeleteDatabase = DeleteDatabase;
53
+ exports.deleteDatabase = deleteDatabase;
59
54
  //# sourceMappingURL=delete_database.js.map
@@ -0,0 +1,3 @@
1
+ import { Context } from "../context";
2
+ import { HashedTable, Structure, Table, FieldSymbol } from "../types";
3
+ export declare function fetchNextCursor(context: Context, cursor: number, target: Structure | Table | FieldSymbol | HashedTable, packageSize: number): Promise<void>;
@@ -0,0 +1,28 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.fetchNextCursor = void 0;
4
+ const types_1 = require("../types");
5
+ const select_1 = require("./select");
6
+ async function fetchNextCursor(context, cursor, target, packageSize) {
7
+ if (target instanceof types_1.FieldSymbol) {
8
+ if (target.isAssigned() === false) {
9
+ throw new Error("GETWA_NOT_ASSIGNED");
10
+ }
11
+ // @ts-ignore
12
+ target = target.getPointer();
13
+ }
14
+ if (target instanceof types_1.Structure) {
15
+ packageSize = 1;
16
+ }
17
+ const result = await context.cursors[cursor].fetchNextCursor(packageSize);
18
+ if (result.rows.length === 0) {
19
+ // @ts-ignore
20
+ abap.builtin.sy.get().subrc.set(4);
21
+ return;
22
+ }
23
+ // @ts-ignore
24
+ abap.builtin.sy.get().subrc.set(0);
25
+ (0, select_1.rowsToTarget)(target, result.rows);
26
+ }
27
+ exports.fetchNextCursor = fetchNextCursor;
28
+ //# sourceMappingURL=fetch_next_cursor.js.map
@@ -95,12 +95,15 @@ export declare class Statements {
95
95
  private _trace;
96
96
  private _traceAsync;
97
97
  _setTrace(min?: number, totals?: boolean): void;
98
+ openCursor(target: INumeric, select: string): Promise<void>;
99
+ fetchNextCursor(cursor: INumeric, target: any, packageSize?: INumeric): Promise<void>;
100
+ closeCursor(cursor: INumeric): Promise<void>;
98
101
  deleteDatabase(table: string | ICharacter, options: IDeleteDatabaseOptions): Promise<void>;
99
102
  insertDatabase(table: string | ICharacter, options: IInsertDatabaseOptions): Promise<number | undefined>;
100
- message(options: IMessageOptions): Promise<void>;
101
103
  modifyDatabase(table: string | ICharacter, options: IModifyDatabaseOptions): Promise<void>;
102
104
  select(target: Structure | Table | FieldSymbol, select: SelectDatabaseOptions, runtimeOptions?: SelectRuntimeOptions): Promise<void>;
103
105
  updateDatabase(table: string | ICharacter, options: IUpdateDatabaseOptions): Promise<number>;
104
106
  callFunction(options: ICallFunctionOptions): Promise<void>;
107
+ message(options: IMessageOptions): Promise<void>;
105
108
  write(source: INumeric | ICharacter | FieldSymbol | string | number, options?: IWriteOptions): void;
106
109
  }
@@ -41,6 +41,9 @@ const set_bit_1 = require("./set_bit");
41
41
  const shift_1 = require("./shift");
42
42
  const sort_1 = require("./sort");
43
43
  const wait_1 = require("./wait");
44
+ const fetch_next_cursor_1 = require("./fetch_next_cursor");
45
+ const open_cursor_1 = require("./open_cursor");
46
+ const close_cursor_1 = require("./close_cursor");
44
47
  const set_handler_1 = require("./set_handler");
45
48
  const split_1 = require("./split");
46
49
  const translate_1 = require("./translate");
@@ -154,27 +157,37 @@ class Statements {
154
157
  }
155
158
  }
156
159
  }
160
+ async openCursor(target, select) {
161
+ const num = await (0, open_cursor_1.openCursor)(this.context, select);
162
+ target.set(num);
163
+ }
164
+ async fetchNextCursor(cursor, target, packageSize) {
165
+ await (0, fetch_next_cursor_1.fetchNextCursor)(this.context, cursor.get(), target, (packageSize === null || packageSize === void 0 ? void 0 : packageSize.get()) || 0);
166
+ }
167
+ async closeCursor(cursor) {
168
+ await (0, close_cursor_1.closeCursor)(this.context, cursor.get());
169
+ }
157
170
  async deleteDatabase(table, options) {
158
- return new delete_database_1.DeleteDatabase(this.context).deleteDatabase(table, options);
171
+ await (0, delete_database_1.deleteDatabase)(table, options, this.context);
159
172
  }
160
173
  async insertDatabase(table, options) {
161
- return new insert_database_1.InsertDatabase(this.context).insertDatabase(table, options);
162
- }
163
- async message(options) {
164
- return new message_1.MessageStatement(this.context).message(options);
174
+ return (0, insert_database_1.insertDatabase)(table, options, this.context);
165
175
  }
166
176
  async modifyDatabase(table, options) {
167
- return new modify_database_1.ModifyDatabase(this.context).modifyDatabase(table, options);
177
+ return (0, modify_database_1.modifyDatabase)(table, options, this.context);
168
178
  }
169
179
  async select(target, select, runtimeOptions) {
170
- return new select_1.SelectDatabase(this.context).select(target, select, runtimeOptions);
180
+ return (0, select_1.select)(target, select, runtimeOptions || {}, this.context);
171
181
  }
172
182
  async updateDatabase(table, options) {
173
- return new update_database_1.UpdateDatabase(this.context).updateDatabase(table, options);
183
+ return (0, update_database_1.updateDatabase)(table, options, this.context);
174
184
  }
175
185
  async callFunction(options) {
176
186
  return new call_function_1.CallFunction(this.context).callFunction(options);
177
187
  }
188
+ async message(options) {
189
+ return new message_1.MessageStatement(this.context).message(options);
190
+ }
178
191
  write(source, options) {
179
192
  return new write_1.WriteStatement(this.context).write(source, options);
180
193
  }
@@ -5,9 +5,6 @@ export declare function toValue(value: any): any;
5
5
  export interface IInsertDatabaseOptions {
6
6
  values?: Structure;
7
7
  table?: Table;
8
+ connection?: string;
8
9
  }
9
- export declare class InsertDatabase {
10
- private readonly context;
11
- constructor(context: Context);
12
- insertDatabase(table: string | ICharacter, options: IInsertDatabaseOptions): Promise<number | undefined>;
13
- }
10
+ export declare function insertDatabase(table: string | ICharacter, options: IInsertDatabaseOptions, context: Context): Promise<number | undefined>;
@@ -1,6 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.InsertDatabase = exports.toValue = void 0;
3
+ exports.insertDatabase = exports.toValue = void 0;
4
4
  const prefix_1 = require("../prefix");
5
5
  function toValue(value) {
6
6
  if (typeof value === "string") {
@@ -13,52 +13,51 @@ function toValue(value) {
13
13
  }
14
14
  }
15
15
  exports.toValue = toValue;
16
- class InsertDatabase {
17
- constructor(context) {
18
- this.context = context;
16
+ async function insertDatabase(table, options, context) {
17
+ const columns = [];
18
+ const values = [];
19
+ if (options.values === undefined && options.table === undefined) {
20
+ throw "insertDatabase, wrong input";
19
21
  }
20
- async insertDatabase(table, options) {
21
- const columns = [];
22
- const values = [];
23
- if (options.values === undefined && options.table === undefined) {
24
- throw "insertDatabase, wrong input";
25
- }
26
- if (options.table !== undefined) {
27
- let subrc = 0;
28
- let dbcnt = 0;
29
- for (const row of options.table.array()) {
30
- await this.insertDatabase(table, { values: row });
31
- // @ts-ignore
32
- subrc = Math.max(subrc, abap.builtin.sy.get().subrc.get());
33
- // @ts-ignore
34
- dbcnt += abap.builtin.sy.get().dbcnt.get();
35
- }
22
+ if (options.table !== undefined) {
23
+ let subrc = 0;
24
+ let dbcnt = 0;
25
+ for (const row of options.table.array()) {
26
+ await insertDatabase(table, { values: row, connection: options.connection }, context);
36
27
  // @ts-ignore
37
- abap.builtin.sy.get().subrc.set(subrc);
28
+ subrc = Math.max(subrc, abap.builtin.sy.get().subrc.get());
38
29
  // @ts-ignore
39
- abap.builtin.sy.get().dbcnt.set(dbcnt);
40
- return;
41
- }
42
- const structure = options.values.get();
43
- for (const k of Object.keys(structure)) {
44
- columns.push(k);
45
- const value = structure[k].get();
46
- values.push(toValue(value));
47
- }
48
- if (typeof table !== "string") {
49
- table = table.get().trimEnd().toLowerCase();
30
+ dbcnt += abap.builtin.sy.get().dbcnt.get();
50
31
  }
51
- const { subrc, dbcnt } = await this.context.defaultDB().insert({
52
- table: (0, prefix_1.buildDbTableName)(table),
53
- columns,
54
- values,
55
- });
56
32
  // @ts-ignore
57
33
  abap.builtin.sy.get().subrc.set(subrc);
58
34
  // @ts-ignore
59
35
  abap.builtin.sy.get().dbcnt.set(dbcnt);
60
- return subrc;
36
+ return;
37
+ }
38
+ const structure = options.values.get();
39
+ for (const k of Object.keys(structure)) {
40
+ columns.push(k);
41
+ const value = structure[k].get();
42
+ values.push(toValue(value));
43
+ }
44
+ if (typeof table !== "string") {
45
+ table = table.get().trimEnd().toLowerCase();
46
+ }
47
+ let db = context.defaultDB();
48
+ if (options.connection) {
49
+ db = context.databaseConnections[options.connection];
61
50
  }
51
+ const { subrc, dbcnt } = await db.insert({
52
+ table: (0, prefix_1.buildDbTableName)(table),
53
+ columns,
54
+ values,
55
+ });
56
+ // @ts-ignore
57
+ abap.builtin.sy.get().subrc.set(subrc);
58
+ // @ts-ignore
59
+ abap.builtin.sy.get().dbcnt.set(dbcnt);
60
+ return subrc;
62
61
  }
63
- exports.InsertDatabase = InsertDatabase;
62
+ exports.insertDatabase = insertDatabase;
64
63
  //# sourceMappingURL=insert_database.js.map
@@ -5,8 +5,4 @@ export interface IModifyDatabaseOptions {
5
5
  values?: Structure | FieldSymbol;
6
6
  table?: Table | FieldSymbol;
7
7
  }
8
- export declare class ModifyDatabase {
9
- private readonly context;
10
- constructor(context: Context);
11
- modifyDatabase(table: string | ICharacter, options: IModifyDatabaseOptions): Promise<void>;
12
- }
8
+ export declare function modifyDatabase(table: string | ICharacter, options: IModifyDatabaseOptions, context: Context): Promise<void>;
@@ -1,40 +1,33 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ModifyDatabase = void 0;
3
+ exports.modifyDatabase = void 0;
4
4
  const types_1 = require("../types");
5
5
  const insert_database_1 = require("./insert_database");
6
6
  const update_database_1 = require("./update_database");
7
- class ModifyDatabase {
8
- constructor(context) {
9
- this.context = context;
7
+ async function modifyDatabase(table, options, context) {
8
+ if (options.table instanceof types_1.FieldSymbol) {
9
+ options.table = options.table.getPointer();
10
10
  }
11
- async modifyDatabase(table, options) {
12
- if (options.table instanceof types_1.FieldSymbol) {
13
- options.table = options.table.getPointer();
14
- }
15
- if (options.values instanceof types_1.FieldSymbol) {
16
- options.values = options.values.getPointer();
17
- }
18
- const insert = new insert_database_1.InsertDatabase(this.context);
19
- const update = new update_database_1.UpdateDatabase(this.context);
20
- if (options.table) {
21
- for (const row of options.table.array()) {
22
- const subrc = await insert.insertDatabase(table, { values: row });
23
- if (subrc !== 0) {
24
- await update.updateDatabase(table, { from: row });
25
- }
26
- }
27
- }
28
- else if (options.values) {
29
- const subrc = await insert.insertDatabase(table, { values: options.values });
11
+ if (options.values instanceof types_1.FieldSymbol) {
12
+ options.values = options.values.getPointer();
13
+ }
14
+ if (options.table) {
15
+ for (const row of options.table.array()) {
16
+ const subrc = await (0, insert_database_1.insertDatabase)(table, { values: row }, context);
30
17
  if (subrc !== 0) {
31
- await update.updateDatabase(table, { from: options.values });
18
+ await (0, update_database_1.updateDatabase)(table, { from: row }, context);
32
19
  }
33
20
  }
34
- else {
35
- throw "modifyDatabase todo";
21
+ }
22
+ else if (options.values) {
23
+ const subrc = await (0, insert_database_1.insertDatabase)(table, { values: options.values }, context);
24
+ if (subrc !== 0) {
25
+ await (0, update_database_1.updateDatabase)(table, { from: options.values }, context);
36
26
  }
37
27
  }
28
+ else {
29
+ throw "modifyDatabase todo";
30
+ }
38
31
  }
39
- exports.ModifyDatabase = ModifyDatabase;
32
+ exports.modifyDatabase = modifyDatabase;
40
33
  //# sourceMappingURL=modify_database.js.map
@@ -0,0 +1,2 @@
1
+ import { Context } from "../context";
2
+ export declare function openCursor(context: Context, select: string): Promise<number>;
@@ -0,0 +1,11 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.openCursor = void 0;
4
+ async function openCursor(context, select) {
5
+ const callbacks = await context.defaultDB().openCursor({ select: select });
6
+ const num = context.cursorCounter++;
7
+ context.cursors[num] = callbacks;
8
+ return num;
9
+ }
10
+ exports.openCursor = openCursor;
11
+ //# sourceMappingURL=open_cursor.js.map
@@ -1,8 +1,5 @@
1
1
  import { Context } from "../context";
2
- import { SelectDatabaseOptions, SelectRuntimeOptions } from "../db/db";
2
+ import { DatabaseRows, SelectDatabaseOptions, SelectRuntimeOptions } from "../db/db";
3
3
  import { FieldSymbol, HashedTable, Structure, Table } from "../types";
4
- export declare class SelectDatabase {
5
- private readonly context;
6
- constructor(context: Context);
7
- select(target: Structure | Table | HashedTable | FieldSymbol, input: SelectDatabaseOptions, runtimeOptions?: SelectRuntimeOptions): Promise<void>;
8
- }
4
+ export declare function select(target: Structure | Table | HashedTable | FieldSymbol, input: SelectDatabaseOptions, runtimeOptions: SelectRuntimeOptions, context: Context): Promise<void>;
5
+ export declare function rowsToTarget(target: Structure | Table | HashedTable | FieldSymbol, rows: DatabaseRows): void;
@@ -1,91 +1,90 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.SelectDatabase = void 0;
3
+ exports.rowsToTarget = exports.select = void 0;
4
4
  const clone_1 = require("../clone");
5
5
  const types_1 = require("../types");
6
- class SelectDatabase {
7
- constructor(context) {
8
- this.context = context;
9
- }
10
- async select(target, input, runtimeOptions) {
11
- var _a, _b;
12
- const { rows: rows } = await this.context.defaultDB().select(input);
13
- if (target instanceof types_1.FieldSymbol) {
14
- if (target.isAssigned() === false) {
15
- throw new Error("GETWA_NOT_ASSIGNED");
16
- }
17
- // @ts-ignore
18
- target = target.getPointer();
6
+ async function select(target, input, runtimeOptions, context) {
7
+ const { rows: rows } = await context.defaultDB().select(input);
8
+ if (target instanceof types_1.FieldSymbol) {
9
+ if (target.isAssigned() === false) {
10
+ throw new Error("GETWA_NOT_ASSIGNED");
19
11
  }
20
- if ((runtimeOptions === null || runtimeOptions === void 0 ? void 0 : runtimeOptions.appending) !== true) {
21
- if (Array.isArray(target)) {
22
- target.forEach(f => f.clear());
23
- }
24
- else {
25
- target === null || target === void 0 ? void 0 : target.clear();
26
- }
12
+ // @ts-ignore
13
+ target = target.getPointer();
14
+ }
15
+ if ((runtimeOptions === null || runtimeOptions === void 0 ? void 0 : runtimeOptions.appending) !== true) {
16
+ if (Array.isArray(target)) {
17
+ target.forEach(f => f.clear());
27
18
  }
28
- if (rows.length === 0) {
29
- // @ts-ignore
30
- abap.builtin.sy.get().dbcnt.set(0);
31
- // @ts-ignore
32
- abap.builtin.sy.get().subrc.set(4);
33
- return;
19
+ else {
20
+ target === null || target === void 0 ? void 0 : target.clear();
34
21
  }
35
- if (target instanceof types_1.Structure) {
36
- const result = {};
37
- for (const column in rows[0]) {
38
- if (rows[0][column] === null || target.get()[column] === undefined) {
39
- continue;
40
- }
41
- result[column] = (0, clone_1.clone)(target.get()[column]).set(rows[0][column]);
22
+ }
23
+ if (rows.length === 0) {
24
+ // @ts-ignore
25
+ abap.builtin.sy.get().dbcnt.set(0);
26
+ // @ts-ignore
27
+ abap.builtin.sy.get().subrc.set(4);
28
+ return;
29
+ }
30
+ rowsToTarget(target, rows);
31
+ if (target === undefined && rows.length === 1) {
32
+ // @ts-ignore
33
+ abap.builtin.sy.get().dbcnt.set(Object.values(rows[0])[0]);
34
+ }
35
+ else {
36
+ // @ts-ignore
37
+ abap.builtin.sy.get().dbcnt.set(rows.length);
38
+ }
39
+ // @ts-ignore
40
+ abap.builtin.sy.get().subrc.set(0);
41
+ }
42
+ exports.select = select;
43
+ function rowsToTarget(target, rows) {
44
+ var _a, _b;
45
+ if (target instanceof types_1.Structure) {
46
+ const result = {};
47
+ for (const column in rows[0]) {
48
+ if (rows[0][column] === null || target.get()[column] === undefined) {
49
+ continue;
42
50
  }
43
- // @ts-ignore
44
- abap.statements.moveCorresponding(new types_1.Structure(result), target);
51
+ result[column] = (0, clone_1.clone)(target.get()[column]).set(rows[0][column]);
45
52
  }
46
- else if (target instanceof types_1.Table || target instanceof types_1.HashedTable) {
47
- for (const row of rows) {
48
- const targetRow = (0, clone_1.clone)(target.getRowType());
49
- if (targetRow instanceof types_1.Structure) {
50
- for (let columnName in row) {
51
- columnName = columnName.toLowerCase();
52
- if (row[columnName] === null) {
53
- (_a = targetRow.get()[columnName]) === null || _a === void 0 ? void 0 : _a.clear();
54
- continue;
55
- }
56
- // @ts-ignore
57
- (_b = targetRow.get()[columnName]) === null || _b === void 0 ? void 0 : _b.set(row[columnName]);
53
+ // @ts-ignore
54
+ abap.statements.moveCorresponding(new types_1.Structure(result), target);
55
+ }
56
+ else if (target instanceof types_1.Table || target instanceof types_1.HashedTable) {
57
+ for (const row of rows) {
58
+ const targetRow = (0, clone_1.clone)(target.getRowType());
59
+ if (targetRow instanceof types_1.Structure) {
60
+ for (let columnName in row) {
61
+ columnName = columnName.toLowerCase();
62
+ if (row[columnName] === null) {
63
+ (_a = targetRow.get()[columnName]) === null || _a === void 0 ? void 0 : _a.clear();
64
+ continue;
58
65
  }
66
+ // @ts-ignore
67
+ (_b = targetRow.get()[columnName]) === null || _b === void 0 ? void 0 : _b.set(row[columnName]);
59
68
  }
60
- else {
61
- const columnName = Object.keys(row)[0];
62
- targetRow.set(row[columnName]);
63
- }
64
- // @ts-ignore
65
- abap.statements.insertInternal({ table: target, data: targetRow, noClone: true });
66
69
  }
67
- }
68
- else if (Array.isArray(target)) {
69
- for (let index = 0; index < target.length; index++) {
70
- const element = target[index];
71
- element.set(rows[0][Object.keys(rows[0])[index]]);
70
+ else {
71
+ const columnName = Object.keys(row)[0];
72
+ targetRow.set(row[columnName]);
72
73
  }
73
- }
74
- else if (target !== undefined) {
75
- // its a simple type
76
- target.set(rows[0][Object.keys(rows[0])[0]]);
77
- }
78
- if (target === undefined && rows.length === 1) {
79
74
  // @ts-ignore
80
- abap.builtin.sy.get().dbcnt.set(Object.values(rows[0])[0]);
75
+ abap.statements.insertInternal({ table: target, data: targetRow, noClone: true });
81
76
  }
82
- else {
83
- // @ts-ignore
84
- abap.builtin.sy.get().dbcnt.set(rows.length);
77
+ }
78
+ else if (Array.isArray(target)) {
79
+ for (let index = 0; index < target.length; index++) {
80
+ const element = target[index];
81
+ element.set(rows[0][Object.keys(rows[0])[index]]);
85
82
  }
86
- // @ts-ignore
87
- abap.builtin.sy.get().subrc.set(0);
83
+ }
84
+ else if (target !== undefined) {
85
+ // its a simple type
86
+ target.set(rows[0][Object.keys(rows[0])[0]]);
88
87
  }
89
88
  }
90
- exports.SelectDatabase = SelectDatabase;
89
+ exports.rowsToTarget = rowsToTarget;
91
90
  //# sourceMappingURL=select.js.map
@@ -7,8 +7,4 @@ export interface IUpdateDatabaseOptions {
7
7
  set?: string[];
8
8
  where?: string;
9
9
  }
10
- export declare class UpdateDatabase {
11
- private readonly context;
12
- constructor(context: Context);
13
- updateDatabase(table: string | ICharacter, options: IUpdateDatabaseOptions): Promise<number>;
14
- }
10
+ export declare function updateDatabase(table: string | ICharacter, options: IUpdateDatabaseOptions, context: Context): Promise<number>;
@@ -1,59 +1,54 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.UpdateDatabase = void 0;
3
+ exports.updateDatabase = void 0;
4
4
  const prefix_1 = require("../prefix");
5
5
  const types_1 = require("../types");
6
6
  const insert_database_1 = require("./insert_database");
7
- class UpdateDatabase {
8
- constructor(context) {
9
- this.context = context;
7
+ async function updateDatabase(table, options, context) {
8
+ if (options.table instanceof types_1.FieldSymbol) {
9
+ options.table = options.table.getPointer();
10
10
  }
11
- async updateDatabase(table, options) {
12
- if (options.table instanceof types_1.FieldSymbol) {
13
- options.table = options.table.getPointer();
14
- }
15
- if (options.from instanceof types_1.FieldSymbol) {
16
- options.from = options.from.getPointer();
17
- }
18
- if (typeof table !== "string") {
19
- table = table.get();
20
- }
21
- // @ts-ignore
22
- const keys = abap.DDIC[table.toUpperCase()].keyFields;
23
- const where = [];
24
- const set = [];
25
- if (options.from) {
26
- const structure = options.from.get();
27
- for (const k of Object.keys(structure)) {
28
- const str = k + " = " + (0, insert_database_1.toValue)(structure[k].get());
29
- if (keys.includes(k.toUpperCase())) {
30
- where.push(str);
31
- }
32
- else {
33
- set.push(str);
34
- }
11
+ if (options.from instanceof types_1.FieldSymbol) {
12
+ options.from = options.from.getPointer();
13
+ }
14
+ if (typeof table !== "string") {
15
+ table = table.get();
16
+ }
17
+ // @ts-ignore
18
+ const keys = abap.DDIC[table.toUpperCase()].keyFields;
19
+ const where = [];
20
+ const set = [];
21
+ if (options.from) {
22
+ const structure = options.from.get();
23
+ for (const k of Object.keys(structure)) {
24
+ const str = k + " = " + (0, insert_database_1.toValue)(structure[k].get());
25
+ if (keys.includes(k.toUpperCase())) {
26
+ where.push(str);
35
27
  }
36
- }
37
- else if (options.set) {
38
- if (options.where) {
39
- where.push(options.where);
28
+ else {
29
+ set.push(str);
40
30
  }
41
- set.push(...options.set);
42
31
  }
43
- else {
44
- throw "updateDatabase, todo";
32
+ }
33
+ else if (options.set) {
34
+ if (options.where) {
35
+ where.push(options.where);
45
36
  }
46
- const { subrc, dbcnt } = await this.context.defaultDB().update({
47
- table: (0, prefix_1.buildDbTableName)(table),
48
- where: where.join(" AND "),
49
- set,
50
- });
51
- // @ts-ignore
52
- abap.builtin.sy.get().subrc.set(subrc);
53
- // @ts-ignore
54
- abap.builtin.sy.get().dbcnt.set(dbcnt);
55
- return subrc;
37
+ set.push(...options.set);
38
+ }
39
+ else {
40
+ throw "updateDatabase, todo";
56
41
  }
42
+ const { subrc, dbcnt } = await context.defaultDB().update({
43
+ table: (0, prefix_1.buildDbTableName)(table),
44
+ where: where.join(" AND "),
45
+ set,
46
+ });
47
+ // @ts-ignore
48
+ abap.builtin.sy.get().subrc.set(subrc);
49
+ // @ts-ignore
50
+ abap.builtin.sy.get().dbcnt.set(dbcnt);
51
+ return subrc;
57
52
  }
58
- exports.UpdateDatabase = UpdateDatabase;
53
+ exports.updateDatabase = updateDatabase;
59
54
  //# sourceMappingURL=update_database.js.map
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@abaplint/runtime",
3
- "version": "2.7.95",
3
+ "version": "2.7.97",
4
4
  "description": "Transpiler - Runtime",
5
5
  "main": "build/src/index.js",
6
6
  "typings": "build/src/index.d.ts",