@abaplint/core
Version:
abaplint - Core API
84 lines • 4.49 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.SQLEscapeHostVariables = exports.SQLEscapeHostVariablesConf = void 0;
const Statements = require("../abap/2_statements/statements");
const Expressions = require("../abap/2_statements/expressions");
const issue_1 = require("../issue");
const _abap_rule_1 = require("./_abap_rule");
const _basic_rule_config_1 = require("./_basic_rule_config");
const version_1 = require("../version");
const _irule_1 = require("./_irule");
const edit_helper_1 = require("../edit_helper");
class SQLEscapeHostVariablesConf extends _basic_rule_config_1.BasicRuleConfig {
}
exports.SQLEscapeHostVariablesConf = SQLEscapeHostVariablesConf;
class SQLEscapeHostVariables extends _abap_rule_1.ABAPRule {
constructor() {
super(...arguments);
this.conf = new SQLEscapeHostVariablesConf();
}
getMetadata() {
return {
key: "sql_escape_host_variables",
title: "Escape SQL host variables",
shortDescription: `Escape SQL host variables, from 740sp05`,
extendedInformation: `https://github.com/SAP/styleguides/blob/main/clean-abap/CleanABAP.md#avoid-obsolete-language-elements`,
tags: [_irule_1.RuleTag.Upport, _irule_1.RuleTag.Styleguide, _irule_1.RuleTag.Quickfix, _irule_1.RuleTag.Syntax],
badExample: `SELECT * FROM tab INTO TABLE res WHERE field = val.`,
goodExample: `SELECT * FROM tab INTO TABLE @res WHERE field = @val.`,
};
}
getConfig() {
return this.conf;
}
setConfig(conf) {
this.conf = conf;
}
runParsed(file, obj) {
const issues = [];
const type = obj.getType();
if (type === "INTF" || type === "TYPE") {
return [];
}
if (this.reg.getConfig().getVersion() < version_1.Version.v740sp02
&& this.reg.getConfig().getVersion() !== version_1.Version.Cloud) {
return [];
}
for (const s of file.getStatements()) {
if (s.get() instanceof Statements.UpdateDatabase
|| s.get() instanceof Statements.ModifyDatabase
|| s.get() instanceof Statements.Select
|| s.get() instanceof Statements.SelectLoop
|| s.get() instanceof Statements.InsertDatabase
|| s.get() instanceof Statements.DeleteDatabase) {
for (const o of s.findAllExpressionsMulti([Expressions.SQLSource, Expressions.SQLSourceSimple])) {
const first = o.getFirstChild();
if (((first === null || first === void 0 ? void 0 : first.get()) instanceof Expressions.Source && first.getChildren()[0].get() instanceof Expressions.FieldChain)
|| ((first === null || first === void 0 ? void 0 : first.get()) instanceof Expressions.SimpleSource3 && first.getChildren()[0].get() instanceof Expressions.FieldChain)) {
const message = "Escape SQL host variables";
const firstToken = o.getFirstChild().getFirstToken();
const fix = edit_helper_1.EditHelper.replaceToken(file, firstToken, "@" + (firstToken === null || firstToken === void 0 ? void 0 : firstToken.getStr()));
const issue = issue_1.Issue.atToken(file, first.getFirstToken(), message, this.getMetadata().key, this.conf.severity, fix);
issues.push(issue);
break;
}
}
for (const o of s.findAllExpressions(Expressions.SQLTarget)) {
const escaped = o.findDirectTokenByText("@");
if (escaped !== undefined) {
continue;
}
const message = "Escape SQL host variables";
const firstToken = o.getFirstChild().getFirstToken();
const fix = edit_helper_1.EditHelper.replaceToken(file, firstToken, "@" + (firstToken === null || firstToken === void 0 ? void 0 : firstToken.getStr()));
const issue = issue_1.Issue.atToken(file, o.getFirstToken(), message, this.getMetadata().key, this.conf.severity, fix);
issues.push(issue);
break;
}
}
}
return issues;
}
}
exports.SQLEscapeHostVariables = SQLEscapeHostVariables;
//# sourceMappingURL=sql_escape_host_variables.js.map