All files / src/abap/2_statements/expressions sql_compare.ts

100% Statements 43/43
100% Branches 1/1
100% Functions 1/1
100% Lines 43/43

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 441x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 3x 1x  
import {ver, seq, optPrio, altPrio, Expression, plusPrio, tok, AlsoIn} from "../combi";
import {SQLSource, SQLFieldName, SQLAliasField, Dynamic, SQLIn, SQLCompareOperator, SQLFunction, SQLAggregation, SQLCase, Source, SimpleSource3, SQLPathForColumn, ConstantString} from ".";
import {Release} from "../../../version";
import {IStatementRunnable} from "../statement_runnable";
import {ParenLeftW, WAt, WParenRightW} from "../../1_lexer/tokens";
import {SQLSetOpGroup} from "./sql_set_op_group";
import {buildSelectCore} from "./_select_core";
import {SQLLikeRegexpr} from "./sql_like_regexpr";
 
export class SQLCompare extends Expression {
  public getRunnable(): IStatementRunnable {
    const subSelect = ver(Release.v750, SQLSetOpGroup, {also: AlsoIn.OpenABAP});
    const simpleSubSelect = seq("(", "SELECT", buildSelectCore(undefined, false), ")");
    const simpleScalarSubSelect = ver(Release.v740sp08, simpleSubSelect, {also: AlsoIn.OpenABAP});
 
    const between = seq("BETWEEN", SQLSource, "AND", SQLSource);
 
    const like = seq("LIKE", SQLSource, optPrio(seq("ESCAPE", SQLSource)));
 
    const nul = seq("IS", optPrio("NOT"), altPrio("NULL", ver(Release.v753, "INITIAL")));
 
    const sub = seq(optPrio(altPrio("ALL", "ANY", "SOME")), altPrio(subSelect, simpleScalarSubSelect));
 
    const source = new SQLSource();
 
    const arith = ver(Release.v750, plusPrio(seq(altPrio("+", "-", "*", "/"), SQLFieldName)), {also: AlsoIn.OpenABAP});
 
    const paren = seq(tok(ParenLeftW), Source, tok(WParenRightW));
    const at = ver(Release.v740sp05, seq(tok(WAt), altPrio(SimpleSource3, paren)), {also: AlsoIn.OpenABAP});
 
    const lhs = altPrio(SQLCase, SQLAggregation, SQLFunction, ConstantString,
                        seq(altPrio(SQLPathForColumn, SQLAliasField, SQLFieldName), optPrio(arith)), at);
    const rhs = altPrio(seq(SQLCompareOperator, altPrio(sub, SQLCase, SQLAggregation, SQLFunction, seq(source, optPrio(arith)))),
                        seq(optPrio("NOT"), altPrio(SQLIn, like, between)),
                        SQLLikeRegexpr,
                        nul);
    const rett = seq(lhs, rhs);
 
    const exists = seq("EXISTS", altPrio(subSelect, simpleSubSelect));
 
    return altPrio(exists, Dynamic, rett);
  }
}