@abaplint/transpiler 2.5.47 → 2.5.48

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.
@@ -40,6 +40,7 @@ export * from "./source_field_symbol";
40
40
  export * from "./source_field";
41
41
  export * from "./source";
42
42
  export * from "./sql_cond";
43
+ export * from "./sql_field";
43
44
  export * from "./sql_from";
44
45
  export * from "./sql_join";
45
46
  export * from "./sql_source_simple";
@@ -56,6 +56,7 @@ __exportStar(require("./source_field_symbol"), exports);
56
56
  __exportStar(require("./source_field"), exports);
57
57
  __exportStar(require("./source"), exports);
58
58
  __exportStar(require("./sql_cond"), exports);
59
+ __exportStar(require("./sql_field"), exports);
59
60
  __exportStar(require("./sql_from"), exports);
60
61
  __exportStar(require("./sql_join"), exports);
61
62
  __exportStar(require("./sql_source_simple"), exports);
@@ -0,0 +1,7 @@
1
+ import { Nodes } from "@abaplint/core";
2
+ import { IExpressionTranspiler } from "./_expression_transpiler";
3
+ import { Traversal } from "../traversal";
4
+ import { Chunk } from "../chunk";
5
+ export declare class SQLField implements IExpressionTranspiler {
6
+ transpile(node: Nodes.ExpressionNode, _traversal: Traversal): Chunk;
7
+ }
@@ -0,0 +1,17 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SQLField = void 0;
4
+ const chunk_1 = require("../chunk");
5
+ class SQLField {
6
+ transpile(node, _traversal) {
7
+ const chunk = new chunk_1.Chunk();
8
+ let concat = node.concatTokens();
9
+ if (concat.includes("~") && concat.split("~")[0].includes("/")) {
10
+ concat = "'" + concat.replace("~", "'~");
11
+ }
12
+ chunk.appendString(concat);
13
+ return chunk;
14
+ }
15
+ }
16
+ exports.SQLField = SQLField;
17
+ //# sourceMappingURL=sql_field.js.map
@@ -9,6 +9,7 @@ class SQLFromTranspiler {
9
9
  const chunk = new chunk_1.Chunk();
10
10
  for (const c of node.getChildren()) {
11
11
  if (c instanceof abaplint.Nodes.TokenNode) {
12
+ // keywords
12
13
  chunk.appendString(c.concatTokens() + " ");
13
14
  }
14
15
  else if (c.get() instanceof abaplint.Expressions.SQLJoin) {
@@ -16,7 +17,15 @@ class SQLFromTranspiler {
16
17
  chunk.appendString(" ");
17
18
  }
18
19
  else {
19
- chunk.appendString(c.concatTokens() + " ");
20
+ if (c.findFirstExpression(abaplint.Expressions.Dynamic)) {
21
+ chunk.appendString(c.concatTokens() + " ");
22
+ }
23
+ else if (c.concatTokens().includes("/")) {
24
+ chunk.appendString("'" + c.concatTokens() + "' ");
25
+ }
26
+ else {
27
+ chunk.appendString(c.concatTokens() + " ");
28
+ }
20
29
  }
21
30
  }
22
31
  return chunk;
@@ -22,14 +22,17 @@ class SelectTranspiler {
22
22
  let select = "SELECT ";
23
23
  const fieldList = node.findFirstExpression(abaplint.Expressions.SQLFieldList)
24
24
  || node.findFirstExpression(abaplint.Expressions.SQLFieldListLoop);
25
- if ((fieldList === null || fieldList === void 0 ? void 0 : fieldList.getChildren().length) === 1) {
26
- select += fieldList.concatTokens();
27
- }
28
- else {
29
- // add commas between field names, this is required for SQLite, and easy to remove in other clients?
30
- select += fieldList === null || fieldList === void 0 ? void 0 : fieldList.findAllExpressions(abaplint.Expressions.SQLField).map(e => e.concatTokens()).join(", ");
25
+ const fields = [];
26
+ for (const f of (fieldList === null || fieldList === void 0 ? void 0 : fieldList.getChildren()) || []) {
27
+ if (f instanceof abaplint.Nodes.ExpressionNode && f.get() instanceof abaplint.Expressions.SQLField) {
28
+ const code = new expressions_1.SQLField().transpile(f, traversal).getCode();
29
+ fields.push(code);
30
+ }
31
+ else {
32
+ fields.push(f.concatTokens());
33
+ }
31
34
  }
32
- select += " ";
35
+ select += fields.join(", ") + " ";
33
36
  const from = node.findFirstExpression(abaplint.Expressions.SQLFrom);
34
37
  if (from) {
35
38
  select += new sql_from_1.SQLFromTranspiler().transpile(from, traversal).getCode();
@@ -83,6 +86,10 @@ class SelectTranspiler {
83
86
  const faeTranspiled = new expressions_1.SQLSourceTranspiler().transpile(fn, traversal).getCode();
84
87
  select = select.replace(new RegExp(" " + escapeRegExp(faeTranspiled), "g"), " " + unique);
85
88
  select = select.replace(unique + ".get().table_line.get()", unique + ".get()"); // there can be only one?
89
+ let by = `Object.keys(${target}.getRowType().get())`;
90
+ if (keys.length > 0) {
91
+ by = JSON.stringify(keys);
92
+ }
86
93
  const code = `if (${faeTranspiled}.array().length === 0) {
87
94
  throw "FAE, todo, empty table";
88
95
  } else {
@@ -90,8 +97,8 @@ class SelectTranspiler {
90
97
  for await (const ${unique} of abap.statements.loop(${faeTranspiled})) {
91
98
  await abap.statements.select(${target}, {select: "${select.trim()}"${extra}}, {appending: true});
92
99
  }
93
- abap.statements.sort(${target}, {by: Object.keys(${target}.getRowType().get()).map(k => { return {component: k}; })});
94
- await abap.statements.deleteInternal(${target}, {adjacent: true});
100
+ abap.statements.sort(${target}, {by: ${by}.map(k => { return {component: k}; })});
101
+ await abap.statements.deleteInternal(${target}, {adjacent: true, by: ${by}});
95
102
  abap.builtin.sy.get().dbcnt.set(${target}.array().length);
96
103
  }`;
97
104
  return new chunk_1.Chunk().append(code, node, traversal);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@abaplint/transpiler",
3
- "version": "2.5.47",
3
+ "version": "2.5.48",
4
4
  "description": "Transpiler",
5
5
  "main": "build/src/index.js",
6
6
  "typings": "build/src/index.d.ts",