public interface SqlParser
This interface defines the contract for all database vendor-specific parsers. Each vendor (Oracle, MySQL, PostgreSQL, etc.) provides its own implementation that handles the vendor-specific tokenization, parsing, and semantic analysis.
Design Pattern: Strategy Pattern
ParserContext (immutable)SqlParseResult (immutable)Usage Example:
// Get parser for specific vendor
SqlParser parser = SqlParserFactory.get(EDbVendor.dbvoracle);
// Build context with inputs
ParserContext context = new ParserContext.Builder(EDbVendor.dbvoracle)
.sqlText("SELECT * FROM employees")
.build();
// Parse and get result
SqlParseResult result = parser.parse(context);
// Access outputs
TStatementList statements = result.getSqlStatements();
ParserContext,
SqlParseResult,
AbstractSqlParser| Modifier and Type | Method and Description |
|---|---|
default TStatementList |
doExtractRawStatements(ParserContext context,
TSourceTokenList tokens)
Deprecated.
As of 3.2.0.0, replaced by
getrawsqlstatements(ParserContext)
which returns a richer SqlParseResult object containing statements,
tokens, errors, timing information, and more. This method only returns
TStatementList without error information.
Migration: Use This method will be removed in a future major version. |
default SqlParseResult |
getrawsqlstatements(ParserContext context)
Extract raw SQL statements without full parsing.
|
EDbVendor |
getVendor()
Get the database vendor this parser handles.
|
SqlParseResult |
parse(ParserContext context)
Parse SQL from the given context.
|
SqlParseResult |
tokenize(ParserContext context)
Tokenize SQL without parsing or statement extraction.
|
EDbVendor getVendor()
SqlParseResult parse(ParserContext context)
This method performs full parsing including:
All inputs come from the context parameter, all outputs go to the result. This ensures clean separation of concerns and thread-safety.
context - immutable context containing all parser inputs
(SQL text, options, callbacks, etc.)SqlParseResult tokenize(ParserContext context)
This method performs only tokenization (lexical analysis):
The result contains tokens but NO statements. Use this when you only need the token stream (e.g., for syntax highlighting, token analysis).
For statement boundaries without full parsing, use getrawsqlstatements(ParserContext).
context - immutable context containing all parser inputsdefault SqlParseResult getrawsqlstatements(ParserContext context)
This method performs:
This is faster than parse(ParserContext) because it skips
detailed syntax checking and semantic analysis. The statements returned
have their tokens grouped correctly but no AST (parse tree) is built.
Use cases:
Equivalent to legacy API: TGSqlParser.getrawsqlstatements()
Default implementation: For parsers still in delegation phase,
this default implementation falls back to tokenize(ParserContext).
Parsers extending AbstractSqlParser override this with proper implementation.
context - immutable context containing all parser inputs@Deprecated default TStatementList doExtractRawStatements(ParserContext context, TSourceTokenList tokens)
getrawsqlstatements(ParserContext)
which returns a richer SqlParseResult object containing statements,
tokens, errors, timing information, and more. This method only returns
TStatementList without error information.
Migration: Use vendorParser.getrawsqlstatements(context)
instead, which performs both tokenization and extraction in a single call
and returns complete result information via SqlParseResult.
This method will be removed in a future major version.
This method is used when tokens are already available from a previous
tokenization step (e.g., via dosqltexttotokenlist()). It performs
only raw statement extraction without repeating tokenization.
Default implementation: Falls back to tokenize() method for vendors that haven't implemented this optimization yet.
context - immutable context containing all parser inputstokens - already-tokenized source token list