SqlScriptSplitter
classin packageklyn.code.sql
public class SqlScriptSplitter extends Object
└ SqlScriptSplitter

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]
Inherited Properties
propertyInherited Properties from Object: type
Methods
Modifier and Type Member Description
public static splitStatements
splitStatements(script as String) as ArrayList<String>
Splits a multi-statement SQL script into trimmed, non-empty SQL statements.
public static splitValidated
splitValidated( script as String, maxScriptSize as Long = 2000000, maxStatements as Long = 100 ) as ArrayList<String> throws ValueException
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.
Inherited Methods
methodInherited Methods from Object: deepCopy, fromJson, hash, toDict, toJson, toMap, toString, toXml