public class Db2SqlParser extends AbstractSqlParser
This parser handles DB2-specific SQL syntax including:
Design Notes:
AbstractSqlParserTLexerDb2, TParserDb2SqlMigrated from TGSqlParser:
SqlParser,
AbstractSqlParser,
TLexerDb2,
TParserDb2SqlAbstractSqlParser.PreparedSqlReader| Modifier and Type | Field and Description |
|---|---|
TLexerDb2 |
flexer |
defaultDelimiterStr, delimiterChar, frameStack, globalContext, globalFrame, lexer, parserContext, sourcetokenlist, sqlcmds, sqlEnv, sqlstatements, syntaxErrors, vendor| Constructor and Description |
|---|
Db2SqlParser()
Construct DB2 SQL parser.
|
| Modifier and Type | Method and Description |
|---|---|
protected void |
extractVendorRawStatements(SqlParseResult.Builder builder)
Call DB2-specific raw statement extraction logic.
|
protected TCustomLexer |
getLexer(ParserContext context)
Return the DB2 lexer instance.
|
protected TCustomParser |
getParser(ParserContext context,
TSourceTokenList tokens)
Return the DB2 SQL parser instance with updated token list.
|
protected TStatementList |
performParsing(ParserContext context,
TCustomParser parser,
TCustomParser secondaryParser,
TSourceTokenList tokens,
TStatementList rawStatements)
Perform full parsing on raw DB2 SQL statements.
|
protected void |
setupVendorParsersForExtraction()
Setup DB2 parser for raw statement extraction.
|
protected void |
tokenizeVendorSql()
Call DB2-specific tokenization logic.
|
String |
toString() |
afterStatementParsed, attemptErrorRecovery, copyErrorsFromStatement, doAfterTokenize, doExtractRawStatements, extractRawStatements, getanewsourcetoken, getDefaultDelimiterStr, getDelimiterChar, getErrorCount, getrawsqlstatements, getSecondaryParser, getSyntaxErrors, getVendor, handleStatementParsingException, initializeGlobalContext, isDollarFunctionDelimiter, onRawStatementComplete, onRawStatementCompleteVendorSpecific, parse, performInterpreter, performSemanticAnalysis, performTokenization, prepareSqlReader, processTokensBeforeParse, processTokensInTokenTable, setTokenHandle, tokenize, towinlinebreakpublic Db2SqlParser()
Configures the parser for IBM DB2 database with default delimiter: at-sign (@)
Following the original TGSqlParser pattern, the lexer and parser are created once in the constructor and reused for all parsing operations.
Note: DB2 uses '@' as the statement delimiter (not ';' like most databases). This is consistent with DB2 stored procedure conventions where @ marks the end of a procedure.
protected TCustomLexer getLexer(ParserContext context)
The lexer is created once in the constructor and reused for all parsing operations. This method simply returns the existing instance, matching the original TGSqlParser pattern where the lexer is created once and reset before each use.
getLexer in class AbstractSqlParsercontext - parser context (not used, lexer already created)protected TCustomParser getParser(ParserContext context, TSourceTokenList tokens)
The parser is created once in the constructor and reused for all parsing operations. This method updates the token list and returns the existing instance, matching the original TGSqlParser pattern.
getParser in class AbstractSqlParsercontext - parser context (not used, parser already created)tokens - source token list to parseprotected void tokenizeVendorSql()
Delegates to dodb2sqltexttotokenlist which handles DB2's specific keyword recognition, JDBC escapes, and token generation.
tokenizeVendorSql in class AbstractSqlParserprotected void setupVendorParsersForExtraction()
DB2 uses a single parser, so we inject sqlcmds and update the token list for the main parser only.
setupVendorParsersForExtraction in class AbstractSqlParserprotected void extractVendorRawStatements(SqlParseResult.Builder builder)
Delegates to dodb2getrawsqlstatements which handles DB2's statement boundaries, stored procedures, and compound blocks.
extractVendorRawStatements in class AbstractSqlParserbuilder - result builder to populateprotected TStatementList performParsing(ParserContext context, TCustomParser parser, TCustomParser secondaryParser, TSourceTokenList tokens, TStatementList rawStatements)
This method parses each raw statement into a complete parse tree, handling stored procedures, functions, triggers, and nested blocks.
performParsing in class AbstractSqlParsercontext - parser contextparser - main parser instancesecondaryParser - secondary parser (null for DB2)tokens - source token listrawStatements - raw statements to parsepublic String toString()
toString in class AbstractSqlParser