Class ScriptParser
java.lang.Object
org.pgcodekeeper.core.parsers.antlr.base.ScriptParser
Parses and analyzes SQL scripts, detecting dangerous statements and syntax errors.
Provides access to parsed script batches and validation results.
-
Constructor Summary
ConstructorsConstructorDescriptionScriptParser(String name, String script, ISettings settings) Creates a new script parser and immediately processes the script. -
Method Summary
Modifier and TypeMethodDescriptionbatch()Gets the parsed script batches (statements).getDangerDdl(Collection<DangerStatement> allowedDangers) Gets the set of dangerous DDL statements not in the allowed set.Gets a formatted error message if parsing encountered errors.booleanisDangerDdl(Collection<DangerStatement> allowedDangers) Checks if the script contains dangerous DDL statements not in the allowed set.
-
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 parsesettings- application settings to use for parsing- Throws:
IOException- if there's an error reading the scriptInterruptedException- if parsing is interrupted
-
-
Method Details
-
batch
Gets the parsed script batches (statements).- Returns:
- list of parsed statement locations and metadata
-
isDangerDdl
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
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
Gets a formatted error message if parsing encountered errors.- Returns:
- formatted error message string, or null if no errors
-
getScript
-