public class OdbcSqlParser extends AbstractSqlParser
This parser handles ODBC-specific SQL syntax including:
Design Notes:
AbstractSqlParser using the template method patternTLexerOdbc for tokenizationTParserOdbc for parsingUsage Example:
// Get ODBC parser from factory
SqlParser parser = SqlParserFactory.get(EDbVendor.dbvodbc);
// Build context
ParserContext context = new ParserContext.Builder(EDbVendor.dbvodbc)
.sqlText("SELECT * FROM Employees WHERE hire_date > { d '2020-01-01' }")
.build();
// Parse
SqlParseResult result = parser.parse(context);
// Access statements
TStatementList statements = result.getSqlStatements();
SqlParser,
AbstractSqlParser,
TLexerOdbc,
TParserOdbcAbstractSqlParser.PreparedSqlReader| Modifier and Type | Field and Description |
|---|---|
TLexerOdbc |
flexer
The ODBC lexer used for tokenization
|
defaultDelimiterStr, delimiterChar, frameStack, globalContext, globalFrame, lexer, parserContext, sourcetokenlist, sqlcmds, sqlEnv, sqlstatements, syntaxErrors, vendor| Constructor and Description |
|---|
OdbcSqlParser()
Construct ODBC SQL parser.
|
| Modifier and Type | Method and Description |
|---|---|
protected void |
extractVendorRawStatements(SqlParseResult.Builder builder)
Call ODBC-specific raw statement extraction logic.
|
protected TCustomLexer |
getLexer(ParserContext context)
Return the ODBC lexer instance.
|
protected TCustomParser |
getParser(ParserContext context,
TSourceTokenList tokens)
Return the ODBC SQL parser instance with updated token list.
|
protected void |
performInterpreter(ParserContext context,
TStatementList statements)
Perform interpretation/evaluation on parsed statements.
|
protected TStatementList |
performParsing(ParserContext context,
TCustomParser parser,
TCustomParser secondaryParser,
TSourceTokenList tokens,
TStatementList rawStatements)
Perform full parsing of statements with syntax checking.
|
protected void |
performSemanticAnalysis(ParserContext context,
TStatementList statements)
Perform ODBC-specific semantic analysis using TSQLResolver.
|
protected void |
setupVendorParsersForExtraction()
Setup ODBC parser for raw statement extraction.
|
protected void |
tokenizeVendorSql()
Call ODBC-specific tokenization logic.
|
afterStatementParsed, attemptErrorRecovery, copyErrorsFromStatement, doAfterTokenize, doExtractRawStatements, extractRawStatements, getanewsourcetoken, getDefaultDelimiterStr, getDelimiterChar, getErrorCount, getrawsqlstatements, getSecondaryParser, getSyntaxErrors, getVendor, handleStatementParsingException, initializeGlobalContext, isDollarFunctionDelimiter, onRawStatementComplete, onRawStatementCompleteVendorSpecific, parse, performTokenization, prepareSqlReader, processTokensBeforeParse, processTokensInTokenTable, setTokenHandle, tokenize, toString, towinlinebreakpublic TLexerOdbc flexer
public OdbcSqlParser()
Configures the parser for ODBC database with default delimiter (;).
Following the original TGSqlParser pattern, the lexer and parser are created once in the constructor and reused for all parsing operations.
protected TCustomLexer getLexer(ParserContext context)
getLexer in class AbstractSqlParsercontext - the parser contextprotected TCustomParser getParser(ParserContext context, TSourceTokenList tokens)
getParser in class AbstractSqlParsercontext - the parser contexttokens - the source token listprotected void tokenizeVendorSql()
Delegates to doodbcsqltexttotokenlist which handles ODBC's specific escape sequences and MSSQL base syntax.
tokenizeVendorSql in class AbstractSqlParserprotected void setupVendorParsersForExtraction()
ODBC 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 doodbcgetrawsqlstatements which handles ODBC's statement delimiters (inherits from MSSQL: semicolon and GO command).
extractVendorRawStatements in class AbstractSqlParserbuilder - the result builder to populate with raw statementsprotected TStatementList performParsing(ParserContext context, TCustomParser parser, TCustomParser secondaryParser, TSourceTokenList tokens, TStatementList rawStatements)
This method orchestrates the parsing of all statements.
performParsing in class AbstractSqlParsercontext - the parser contextparser - the main parser instancesecondaryParser - secondary parser (may be null)tokens - the source token listrawStatements - raw statements already extracted (never null)protected void performSemanticAnalysis(ParserContext context, TStatementList statements)
performSemanticAnalysis in class AbstractSqlParsercontext - the parser contextstatements - the parsed statements (mutable)protected void performInterpreter(ParserContext context, TStatementList statements)
performInterpreter in class AbstractSqlParsercontext - the parser contextstatements - the parsed statements (mutable)