Statement Splitter
Dialect-aware SQL script splitting for multi-statement scripts, migration files,
and procedural blocks.
Classes
-
class sqlspec.core.splitter.StatementSplitter[source]
Bases: object
SQL script splitter with caching and dialect support.
-
__init__(dialect, strip_trailing_semicolon=False)[source]
Initialize the statement splitter.
- Parameters:
-
-
split(sql)[source]
Split SQL script into individual statements.
- Parameters:
sql (str) -- The SQL script to split
- Return type:
list[str]
- Returns:
List of individual SQL statements
-
class sqlspec.core.splitter.DialectConfig[source]
Bases: object
Abstract base class for SQL dialect configurations.
-
__init__()[source]
Initialize dialect configuration.
-
abstract property name: str
Name of the dialect.
-
abstract property block_starters: set[str]
Keywords that start a block.
-
abstract property block_enders: set[str]
Keywords that end a block.
-
abstract property statement_terminators: set[str]
Characters that terminate statements.
-
property batch_separators: set[str]
Keywords that separate batches.
-
property special_terminators: dict[str, Callable[[list[Token], int], bool]]
Special terminators that need custom handling.
-
property max_nesting_depth: int
Maximum allowed nesting depth for blocks.
-
get_all_token_patterns()[source]
Get the complete ordered list of token patterns for this dialect.
- Return type:
list[tuple[TokenType, str | Callable[[str, int, int, int], Token | None]]]
- Returns:
List of tuples containing token types and their regex patterns
-
static is_real_block_ender(tokens, current_pos)[source]
Check if END keyword represents an actual block terminator.
- Parameters:
-
- Return type:
bool
- Returns:
True if END represents a block terminator, False otherwise
-
should_delay_semicolon_termination(tokens, current_pos)[source]
Check if semicolon termination should be delayed.
- Parameters:
-
- Return type:
bool
- Returns:
True if termination should be delayed, False otherwise
-
class sqlspec.core.splitter.PostgreSQLDialectConfig[source]
Bases: _EagerDialectConfig
Configuration for PostgreSQL dialect with dollar-quoted strings.
-
class sqlspec.core.splitter.OracleDialectConfig[source]
Bases: _EagerDialectConfig
Configuration for Oracle PL/SQL dialect.
-
should_delay_semicolon_termination(tokens, current_pos)[source]
Check if semicolon termination should be delayed for Oracle slash terminators.
- Parameters:
-
- Return type:
bool
- Returns:
True if termination should be delayed, False otherwise
-
static is_real_block_ender(tokens, current_pos)[source]
Check if END keyword represents a block terminator in Oracle PL/SQL.
- Parameters:
-
- Return type:
bool
- Returns:
True if END represents a block terminator, False otherwise
-
class sqlspec.core.splitter.TSQLDialectConfig[source]
Bases: _EagerDialectConfig
Configuration for T-SQL (SQL Server) dialect.
Functions
-
sqlspec.core.splitter.split_sql_script(script, dialect=None, strip_trailing_terminator=False)[source]
Split SQL script into individual statements.
- Parameters:
script (str) -- The SQL script to split
dialect (str | None) -- The SQL dialect name
strip_trailing_terminator (bool) -- If True, remove trailing terminators from statements
- Return type:
list[str]
- Returns:
List of individual SQL statements