All files / src/abap/5_syntax/statements update_database.ts

93.33% Statements 56/60
69.23% Branches 9/13
100% Functions 1/1
93.33% Lines 56/60

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 611x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 5x 3x 3x 6x 6x 6x 6x 3x 5x 5x 5x     5x 9x 9x 5x 5x     5x 5x 3x 3x 5x 5x 1x  
import * as Expressions from "../../2_statements/expressions";
import {StatementNode} from "../../nodes";
import {Source} from "../expressions/source";
import {ScopeType} from "../_scope_type";
import {StructureType} from "../../types/basic";
import {TypedIdentifier} from "../../types/_typed_identifier";
import {Identifier} from "../../1_lexer/tokens/identifier";
import {DatabaseTable} from "../expressions/database_table";
import {Dynamic} from "../expressions/dynamic";
import {StatementSyntax} from "../_statement_syntax";
import {SyntaxInput} from "../_syntax_input";
import {checkDatabaseFields} from "../expressions/_check_database_fields";
 
export class UpdateDatabase implements StatementSyntax {
  public runSyntax(node: StatementNode, input: SyntaxInput): void {
 
    const dbtab = node.findFirstExpression(Expressions.DatabaseTable);
    if (dbtab !== undefined) {
      const dbSource = DatabaseTable.runSyntax(dbtab, input);
      const fields = node.findAllExpressions(Expressions.SQLFieldAndValue)
        .flatMap(fieldAndValue => fieldAndValue.findDirectExpressions(Expressions.SQLFieldName))
        .map(field => field.concatTokens().toUpperCase());
      fields.push(...node.findAllExpressions(Expressions.SQLCompare)
        .map(compare => compare.findDirectExpression(Expressions.SQLFieldName)?.concatTokens().toUpperCase())
        .filter(field => field !== undefined));
      checkDatabaseFields(fields, [dbSource], input, node.getFirstToken());
    }
 
    const tableName = node.findDirectExpression(Expressions.DatabaseTable);
    const tokenName = tableName?.getFirstToken();
    if (tableName && tokenName) {
      // todo, this also finds structures, it should only find transparent tables
      const found = input.scope.getDDIC().lookupTable(tokenName.getStr());
      if (found instanceof StructureType) {
        input.scope.push(ScopeType.OpenSQL, "UPDATE", tokenName.getStart(), input.filename);
        for (const field of found.getComponents()) {
          const fieldToken = new Identifier(node.getFirstToken().getStart(), field.name);
          const id = new TypedIdentifier(fieldToken, input.filename, field.type);
          input.scope.addIdentifier(id);
        }
      }
    }
 
    for (const s of node.findAllExpressions(Expressions.Source)) {
      Source.runSyntax(s, input);
    }
    for (const s of node.findAllExpressions(Expressions.SimpleSource3)) {
      Source.runSyntax(s, input);
    }
 
    for (const d of node.findAllExpressions(Expressions.Dynamic)) {
      Dynamic.runSyntax(d, input);
    }
 
    if (input.scope.getType() === ScopeType.OpenSQL) {
      input.scope.pop(node.getLastToken().getEnd());
    }
 
  }
}