Class Db2SqlParser
- All Implemented Interfaces:
SqlParser
This parser handles DB2-specific SQL syntax including:
- DB2 SQL procedures and functions
- DB2-specific triggers
- DECLARE CURSOR and compound statements
- DB2 echo commands treated as SQL*Plus commands
- JDBC escape sequences
- WITH isolation clauses
Design Notes:
- Extends
AbstractSqlParser - Can directly instantiate:
TLexerDb2,TParserDb2Sql - Uses single parser (no secondary parser)
- Delimiter character: '@' for stored procedures (not ';')
Migrated from TGSqlParser:
- dodb2sqltexttotokenlist() → tokenizeVendorSql()
- dodb2getrawsqlstatements() → extractVendorRawStatements()
- Since:
- 3.2.0.0
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class gudusoft.gsqlparser.parser.AbstractSqlParser
AbstractSqlParser.PreparedSqlReader -
Field Summary
FieldsFields inherited from class gudusoft.gsqlparser.parser.AbstractSqlParser
defaultDelimiterStr, delimiterChar, frameStack, globalContext, globalFrame, lexer, parserContext, sourcetokenlist, sqlcmds, sqlEnv, sqlstatements, syntaxErrors, vendor -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprotected voidCall DB2-specific raw statement extraction logic.protected TCustomLexergetLexer(ParserContext context) Return the DB2 lexer instance.protected TCustomParsergetParser(ParserContext context, TSourceTokenList tokens) Return the DB2 SQL parser instance with updated token list.protected TStatementListperformParsing(ParserContext context, TCustomParser parser, TCustomParser secondaryParser, TSourceTokenList tokens, TStatementList rawStatements) Perform full parsing on raw DB2 SQL statements.protected voidSetup DB2 parser for raw statement extraction.protected voidCall DB2-specific tokenization logic.toString()Methods inherited from class gudusoft.gsqlparser.parser.AbstractSqlParser
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, towinlinebreak
-
Field Details
-
flexer
-
-
Constructor Details
-
Db2SqlParser
public Db2SqlParser()Construct DB2 SQL parser.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.
-
-
Method Details
-
getLexer
Return the DB2 lexer instance.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.
- Specified by:
getLexerin classAbstractSqlParser- Parameters:
context- parser context (not used, lexer already created)- Returns:
- the DB2 lexer instance created in constructor
-
getParser
Return the DB2 SQL parser instance with updated token list.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.
- Specified by:
getParserin classAbstractSqlParser- Parameters:
context- parser context (not used, parser already created)tokens- source token list to parse- Returns:
- the DB2 SQL parser instance created in constructor
-
tokenizeVendorSql
Call DB2-specific tokenization logic.Delegates to dodb2sqltexttotokenlist which handles DB2's specific keyword recognition, JDBC escapes, and token generation.
- Specified by:
tokenizeVendorSqlin classAbstractSqlParser
-
setupVendorParsersForExtraction
Setup DB2 parser for raw statement extraction.DB2 uses a single parser, so we inject sqlcmds and update the token list for the main parser only.
- Specified by:
setupVendorParsersForExtractionin classAbstractSqlParser
-
extractVendorRawStatements
Call DB2-specific raw statement extraction logic.Delegates to dodb2getrawsqlstatements which handles DB2's statement boundaries, stored procedures, and compound blocks.
- Specified by:
extractVendorRawStatementsin classAbstractSqlParser- Parameters:
builder- result builder to populate
-
performParsing
protected TStatementList performParsing(ParserContext context, TCustomParser parser, TCustomParser secondaryParser, TSourceTokenList tokens, TStatementList rawStatements) Perform full parsing on raw DB2 SQL statements.This method parses each raw statement into a complete parse tree, handling stored procedures, functions, triggers, and nested blocks.
- Specified by:
performParsingin classAbstractSqlParser- Parameters:
context- parser contextparser- main parser instancesecondaryParser- secondary parser (null for DB2)tokens- source token listrawStatements- raw statements to parse- Returns:
- list of parsed statements
-
toString
- Overrides:
toStringin classAbstractSqlParser
-