public class OracleSqlParser extends AbstractSqlParser
This parser handles Oracle-specific SQL syntax including:
Implementation Status: PHASE 3 - IN PROGRESS
Design Notes:
SqlParser directly (will extend AbstractSqlParser in Phase 4)TLexerOracle, TParserOracleSql, TParserOraclePLSqlUsage Example:
// Get Oracle parser from factory
SqlParser parser = SqlParserFactory.get(EDbVendor.dbvoracle);
// Build context
ParserContext context = new ParserContext.Builder(EDbVendor.dbvoracle)
.sqlText("SELECT * FROM emp WHERE deptno = 10")
.build();
// Parse
SqlParseResult result = parser.parse(context);
// Access statements
TStatementList statements = result.getSqlStatements();
Phase 3 Extraction Roadmap:
Key Methods to Extract from TGSqlParser:
dooraclesqltexttotokenlist() - Oracle tokenization with SQL*Plus command detectiondooraclegetrawsqlstatements() - Oracle raw statement boundaries (handles PL/SQL blocks)getanewsourcetoken() - Token iterator from lexergetprevsolidtoken() - Navigate token list backwardsIsValidPlaceForDivToSqlplusCmd() - Slash vs divide operator disambiguationcountLines() - Multi-line token handlingspaceAtTheEndOfReturnToken() - SQL*Plus command validationSqlParser,
AbstractSqlParser,
TLexerOracle,
TParserOracleSql,
TParserOraclePLSqlAbstractSqlParser.PreparedSqlReader| Modifier and Type | Field and Description |
|---|---|
TLexerOracle |
flexer
The Oracle lexer used for tokenization
|
defaultDelimiterStr, delimiterChar, frameStack, globalContext, globalFrame, lexer, parserContext, sourcetokenlist, sqlcmds, sqlEnv, sqlstatements, syntaxErrors, vendor| Constructor and Description |
|---|
OracleSqlParser()
Construct Oracle SQL parser.
|
| Modifier and Type | Method and Description |
|---|---|
protected void |
afterStatementParsed(TCustomSqlStatement stmt)
Override to provide Oracle-specific post-processing after statement parsing.
|
protected void |
extractVendorRawStatements(SqlParseResult.Builder builder)
Call Oracle-specific raw statement extraction logic.
|
protected TCustomLexer |
getLexer(ParserContext context)
Return the Oracle lexer instance.
|
protected TCustomParser |
getParser(ParserContext context,
TSourceTokenList tokens)
Return the Oracle SQL parser instance with updated token list.
|
protected TCustomParser |
getSecondaryParser(ParserContext context,
TSourceTokenList tokens)
Return the Oracle PL/SQL parser instance with updated token list.
|
protected void |
performInterpreter(ParserContext context,
TStatementList statements)
Perform Oracle-specific AST interpretation/evaluation using TASTEvaluator.
|
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 Oracle-specific semantic analysis using TSQLResolver.
|
protected void |
setupVendorParsersForExtraction()
Setup Oracle parsers for raw statement extraction.
|
protected void |
tokenizeVendorSql()
Call Oracle-specific tokenization logic.
|
String |
toString()
Copy syntax errors from a statement to our error list.
|
attemptErrorRecovery, copyErrorsFromStatement, doAfterTokenize, doExtractRawStatements, extractRawStatements, getanewsourcetoken, getDefaultDelimiterStr, getDelimiterChar, getErrorCount, getrawsqlstatements, getSyntaxErrors, getVendor, handleStatementParsingException, initializeGlobalContext, isDollarFunctionDelimiter, onRawStatementComplete, onRawStatementCompleteVendorSpecific, parse, performTokenization, prepareSqlReader, processTokensBeforeParse, processTokensInTokenTable, setTokenHandle, tokenize, towinlinebreakpublic TLexerOracle flexer
public OracleSqlParser()
Configures the parser for Oracle database with default delimiters:
Following the original TGSqlParser pattern, the lexer and parsers are created once in the constructor and reused for all parsing operations. This avoids unnecessary object allocation overhead since the parser is not thread-safe and designed for single-use per instance.
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 TCustomParser getSecondaryParser(ParserContext context, TSourceTokenList tokens)
Oracle needs a secondary parser (TParserOraclePLSql) for PL/SQL blocks (procedures, functions, packages, triggers, anonymous blocks).
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.
getSecondaryParser in class AbstractSqlParsercontext - parser context (not used, parser already created)tokens - source token list to parseprotected void tokenizeVendorSql()
Delegates to dooraclesqltexttotokenlist which handles Oracle's specific keyword recognition, SQL*Plus commands, forward slash disambiguation, and token generation.
tokenizeVendorSql in class AbstractSqlParserprotected void setupVendorParsersForExtraction()
Oracle uses dual parsers (SQL + PL/SQL), so we inject sqlcmds and update token lists for both parsers.
setupVendorParsersForExtraction in class AbstractSqlParserprotected void extractVendorRawStatements(SqlParseResult.Builder builder)
Delegates to dooraclegetrawsqlstatements which handles Oracle's statement delimiters (semicolon and forward slash).
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 by:
Important: This method does NOT extract raw statements - they are
passed in as a parameter already extracted by AbstractSqlParser.extractRawStatements(gudusoft.gsqlparser.parser.ParserContext, gudusoft.gsqlparser.TSourceTokenList, gudusoft.gsqlparser.TCustomLexer, long).
This eliminates duplicate extraction that was occurring in the old design.
Extracted from: TGSqlParser.doparse() lines 16903-17026
performParsing in class AbstractSqlParsercontext - parser contextparser - main SQL parser (TParserOracleSql)secondaryParser - PL/SQL parser (TParserOraclePLSql)tokens - source token listrawStatements - raw statements already extracted (never null)protected void afterStatementParsed(TCustomSqlStatement stmt)
For Oracle, we check if the statement is PL/SQL and recursively find syntax errors in nested PL/SQL statements.
afterStatementParsed in class AbstractSqlParserstmt - the statement that was just parsedprotected void performSemanticAnalysis(ParserContext context, TStatementList statements)
This includes:
performSemanticAnalysis in class AbstractSqlParsercontext - the parser contextstatements - the parsed statementsprotected void performInterpreter(ParserContext context, TStatementList statements)
This executes simple SQL statements and evaluates expressions for static analysis and constant folding.
performInterpreter in class AbstractSqlParsercontext - the parser contextstatements - the parsed statementspublic String toString()
toString in class AbstractSqlParser