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

95.92% Statements 47/49
83.33% Branches 10/12
100% Functions 1/1
95.92% Lines 47/49

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 491x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 1x 3x 3x 3x 3x 3x 2x 2x 3x 3x 2x 2x 2x 1x 1x 2x 2x 2x 2x 1x 2x 2x 3x 3x 3x 2x 3x     2x 3x 1x 1x 3x 3x 1x
import * as Expressions from "../../2_statements/expressions";
import {StatementNode} from "../../nodes";
import {CurrentScope} from "../_current_scope";
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";
 
export class UpdateDatabase implements StatementSyntax {
  public runSyntax(node: StatementNode, scope: CurrentScope, filename: string): void {
 
    const dbtab = node.findFirstExpression(Expressions.DatabaseTable);
    if (dbtab !== undefined) {
      new DatabaseTable().runSyntax(dbtab, scope, filename);
    }
 
    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 = scope.getDDIC().lookupTable(tokenName.getStr());
      if (found instanceof StructureType) {
        scope.push(ScopeType.OpenSQL, "UPDATE", tokenName.getStart(), filename);
        for (const field of found.getComponents()) {
          const fieldToken = new Identifier(node.getFirstToken().getStart(), field.name);
          const id = new TypedIdentifier(fieldToken, filename, field.type);
          scope.addIdentifier(id);
        }
      }
    }
 
    for (const s of node.findAllExpressions(Expressions.Source)) {
      new Source().runSyntax(s, scope, filename);
    }
 
    for (const d of node.findAllExpressions(Expressions.Dynamic)) {
      new Dynamic().runSyntax(d, scope, filename);
    }
 
    if (scope.getType() === ScopeType.OpenSQL) {
      scope.pop(node.getLastToken().getEnd());
    }
 
  }
}