Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 | 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 22x 22x 22x 3x 3x 3x 19x 22x 14x 14x 14x 14x 14x 14x 14x 1x 1x 1x 1x 14x 1x 1x 1x 1x 1x 14x 12x 12x 5x 22x 2x 2x 5x 5x 5x 5x 5x 1x 1x 1x 9x 9x 1x 1x 8x 8x 1x 1x | import * as Expressions from "../../2_statements/expressions";
import {ExpressionNode, StatementNode} from "../../nodes";
import {AnyType, StructureType, TableType, UnknownType, VoidType} from "../../types/basic";
import {AbstractType} from "../../types/basic/_abstract_type";
import {SyntaxInput, syntaxIssue} from "../_syntax_input";
import {SQLSetOpGroup} from "./sql_set_op_group";
import {SQLSource} from "./sql_source";
const RANGE_COMPONENTS = ["SIGN", "OPTION", "LOW", "HIGH"];
export class SQLIn {
public static runSyntax(node: ExpressionNode | StatementNode, input: SyntaxInput): void {
const setop = node.findDirectExpression(Expressions.SQLSetOpGroup);
if (setop) {
SQLSetOpGroup.runSyntax(setop, input);
return;
}
if (node.getChildren().length === 2) {
const insource = node.findFirstExpression(Expressions.SQLSource);
if (insource) {
const intype = SQLSource.runSyntax(insource, input);
if (intype &&
!(intype instanceof VoidType) &&
!(intype instanceof UnknownType) &&
!(intype instanceof TableType)) {
const message = "IN, not a table";
input.issues.push(syntaxIssue(input, node.getFirstToken(), message));
return;
}
if (intype instanceof TableType && this.isRangeRow(intype.getRowType()) === false) {
const name = insource.concatTokens().replace(/^@/, "").replace(/\[\]$/, "");
const message = `row structure of ${name} is not correct`;
input.issues.push(syntaxIssue(input, node.getFirstToken(), message));
return;
}
}
return;
}
for (const s of node.findDirectExpressions(Expressions.SQLSource)) {
SQLSource.runSyntax(s, input);
}
for (const s of node.findDirectExpressions(Expressions.SQLSourceNoSpace)) {
SQLSource.runSyntax(s, input);
}
}
// "IN itab" expects a ranges table, ie. the row must have SIGN, OPTION, LOW and HIGH
private static isRangeRow(rowType: AbstractType): boolean {
if (rowType instanceof VoidType || rowType instanceof UnknownType || rowType instanceof AnyType) {
return true;
} else if (!(rowType instanceof StructureType)) {
return false;
}
return RANGE_COMPONENTS.every(c => rowType.getComponentByName(c) !== undefined);
}
}
|