public class SqlScriptSplitter extends Object
Splits multi-statement SQL scripts into individual executable SQL statements without breaking on semicolons inside single/double/backtick quotes, PostgreSQL $$...$$ / $tag$...$tag$ dollar-quoted blocks, or -- / # / block comments.
Also supports MySQL DELIMITER directives and T-SQL GO batch separators.
import klyn.code.sql script = "CREATE TABLE t (id INT, note TEXT DEFAULT 'a;b'); -- comment; here\nINSERT INTO t VALUES (1, 'ok');" stmts = SqlScriptSplitter.splitStatements(script) assert stmts.size == 2 assert "DEFAULT 'a;b'" in stmts[0]
| Modifier and Type | Member | Description |
|---|---|---|
| public static | splitStatements | Splits a multi-statement SQL script into trimmed, non-empty SQL statements. |
| public static | splitValidated | Validates and splits a multi-statement SQL script, raising ValueException when the script is empty, exceeds maxScriptSize or maxStatements, has an invalid DELIMITER directive, or contains an unterminated literal or block comment. |