UNPKG

@abaplint/core

Version:
83 lines 3.73 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.SQLCompare = void 0; const Expressions = require("../../2_statements/expressions"); const nodes_1 = require("../../nodes"); const basic_1 = require("../../types/basic"); const dynamic_1 = require("./dynamic"); const source_1 = require("./source"); const sql_in_1 = require("./sql_in"); const sql_source_1 = require("./sql_source"); class SQLCompare { static runSyntax(node, input, tables) { var _a, _b; let sourceType; let token; if (((_a = node.getFirstChild()) === null || _a === void 0 ? void 0 : _a.get()) instanceof Expressions.Dynamic) { dynamic_1.Dynamic.runSyntax(node.getFirstChild(), input); return; } for (const s of node.findDirectExpressions(Expressions.SimpleSource3)) { source_1.Source.runSyntax(s, input); } for (const s of node.findDirectExpressions(Expressions.SQLSource)) { for (const child of s.getChildren()) { if (child instanceof nodes_1.ExpressionNode) { token = child.getFirstToken(); break; } } sourceType = sql_source_1.SQLSource.runSyntax(s, input); } const sqlin = node.findDirectExpression(Expressions.SQLIn); if (sqlin) { sql_in_1.SQLIn.runSyntax(sqlin, input); } const fieldName = (_b = node.findDirectExpression(Expressions.SQLFieldName)) === null || _b === void 0 ? void 0 : _b.concatTokens(); if (fieldName && sourceType && token) { // check compatibility for rule sql_value_conversion const targetType = this.findType(fieldName, tables, input.scope); let message = ""; if (sourceType instanceof basic_1.IntegerType && targetType instanceof basic_1.CharacterType) { message = "Integer to CHAR conversion"; } else if (sourceType instanceof basic_1.IntegerType && targetType instanceof basic_1.NumericType) { message = "Integer to NUMC conversion"; } else if (sourceType instanceof basic_1.NumericType && targetType instanceof basic_1.IntegerType) { message = "NUMC to Integer conversion"; } else if (sourceType instanceof basic_1.CharacterType && targetType instanceof basic_1.IntegerType) { message = "CHAR to Integer conversion"; } else if (sourceType instanceof basic_1.CharacterType && targetType instanceof basic_1.CharacterType && sourceType.getLength() > targetType.getLength()) { message = "Source field longer than database field, CHAR -> CHAR"; } else if (sourceType instanceof basic_1.NumericType && targetType instanceof basic_1.NumericType && sourceType.getLength() > targetType.getLength()) { message = "Source field longer than database field, NUMC -> NUMC"; } if (message !== "") { input.scope.addSQLConversion(fieldName, message, token); } } } static findType(fieldName, tables, scope) { for (const t of tables) { const type = t === null || t === void 0 ? void 0 : t.parseType(scope.getRegistry()); if (type instanceof basic_1.StructureType) { return type.getComponentByName(fieldName); } } return undefined; } } exports.SQLCompare = SQLCompare; //# sourceMappingURL=sql_compare.js.map