Class ScriptParser

java.lang.Object
org.pgcodekeeper.core.parsers.antlr.base.ScriptParser

public final class ScriptParser extends Object
Parses and analyzes SQL scripts, detecting dangerous statements and syntax errors. Provides access to parsed script batches and validation results.
  • Constructor Details

    • ScriptParser

      public ScriptParser(String name, String script, ISettings settings) throws IOException, InterruptedException
      Creates a new script parser and immediately processes the script.
      Parameters:
      name - name of the script (for error reporting)
      script - the SQL script content to parse
      settings - application settings to use for parsing
      Throws:
      IOException - if there's an error reading the script
      InterruptedException - if parsing is interrupted
  • Method Details

    • batch

      public List<PgObjLocation> batch()
      Gets the parsed script batches (statements).
      Returns:
      list of parsed statement locations and metadata
    • isDangerDdl

      public boolean isDangerDdl(Collection<DangerStatement> allowedDangers)
      Checks if the script contains dangerous DDL statements not in the allowed set.
      Parameters:
      allowedDangers - collection of dangerous statements that are permitted
      Returns:
      true if script contains unapproved dangerous statements
    • getDangerDdl

      public Set<DangerStatement> getDangerDdl(Collection<DangerStatement> allowedDangers)
      Gets the set of dangerous DDL statements not in the allowed set.
      Parameters:
      allowedDangers - collection of dangerous statements that are permitted
      Returns:
      set of unapproved dangerous statements found in script
    • getErrorMessage

      public String getErrorMessage()
      Gets a formatted error message if parsing encountered errors.
      Returns:
      formatted error message string, or null if no errors
    • getScript

      public String getScript()