Class OracleSqlParser
- All Implemented Interfaces:
SqlParser
This parser handles Oracle-specific SQL syntax including:
- PL/SQL blocks (procedures, functions, packages, triggers)
- SQL*Plus commands (spool, set, show, etc.)
- Oracle-specific DML/DDL (MERGE, flashback, etc.)
- Oracle analytical functions and extensions
- Special token handling (INNER, NOT DEFERRABLE, etc.)
Implementation Status: PHASE 3 - IN PROGRESS
- Completed: Oracle classes (TLexerOracle, TParserOracleSql, TParserOraclePLSql) are now PUBLIC
- Current: Skeleton implementation delegates to legacy TGSqlParser
- Next: Extract vendor-specific logic from TGSqlParser into this class
- Goal: Fully self-contained Oracle parser using AbstractSqlParser template
Design Notes:
- Implements
SqlParserdirectly (will extendAbstractSqlParserin Phase 4) - Can now directly instantiate:
TLexerOracle,TParserOracleSql,TParserOraclePLSql - Uses two parsers: TParserOracleSql (SQL) + TParserOraclePLSql (PL/SQL blocks)
- Handles SQL*Plus commands via special tokenization logic
- Delimiter character: '/' for PL/SQL blocks, ';' for SQL statements
Usage 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:
- ✅ DONE: Make TLexerOracle, TParserOracleSql, TParserOraclePLSql public
- ⏳ TODO: Extract tokenization logic (~367 lines from TGSqlParser.dooraclesqltexttotokenlist())
- ⏳ TODO: Extract raw statement logic (~200 lines from TGSqlParser.dooraclegetrawsqlstatements())
- ⏳ TODO: Extract parsing orchestration (SQL vs PL/SQL parser selection)
- ⏳ TODO: Extract helper methods (getanewsourcetoken, getprevsolidtoken, etc.)
- ⏳ TODO: Extend AbstractSqlParser and use template method pattern fully
- ⏳ TODO: Remove all delegation to TGSqlParser
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 validation
- 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 voidOverride to provide Oracle-specific post-processing after statement parsing.protected voidCall Oracle-specific raw statement extraction logic.protected TCustomLexergetLexer(ParserContext context) Return the Oracle lexer instance.protected TCustomParsergetParser(ParserContext context, TSourceTokenList tokens) Return the Oracle SQL parser instance with updated token list.protected TCustomParsergetSecondaryParser(ParserContext context, TSourceTokenList tokens) Return the Oracle PL/SQL parser instance with updated token list.protected voidperformInterpreter(ParserContext context, TStatementList statements) Perform Oracle-specific AST interpretation/evaluation using TASTEvaluator.protected TStatementListperformParsing(ParserContext context, TCustomParser parser, TCustomParser secondaryParser, TSourceTokenList tokens, TStatementList rawStatements) Perform full parsing of statements with syntax checking.protected voidperformSemanticAnalysis(ParserContext context, TStatementList statements) Perform Oracle-specific semantic analysis using TSQLResolver.protected voidSetup Oracle parsers for raw statement extraction.protected voidCall Oracle-specific tokenization logic.toString()Copy syntax errors from a statement to our error list.Methods inherited from class gudusoft.gsqlparser.parser.AbstractSqlParser
attemptErrorRecovery, copyErrorsFromStatement, doAfterTokenize, doExtractRawStatements, extractRawStatements, getanewsourcetoken, getDefaultDelimiterStr, getDelimiterChar, getErrorCount, getrawsqlstatements, getSyntaxErrors, getVendor, handleStatementParsingException, initializeGlobalContext, isDollarFunctionDelimiter, onRawStatementComplete, onRawStatementCompleteVendorSpecific, parse, performTokenization, prepareSqlReader, processTokensBeforeParse, processTokensInTokenTable, setTokenHandle, tokenize, towinlinebreak
-
Field Details
-
flexer
The Oracle lexer used for tokenization
-
-
Constructor Details
-
OracleSqlParser
public OracleSqlParser()Construct Oracle SQL parser.Configures the parser for Oracle database with default delimiters:
- SQL statements: semicolon (;)
- PL/SQL blocks: forward slash (/)
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.
-
-
Method Details
-
getLexer
Return the Oracle 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 Oracle lexer instance created in constructor
-
getParser
Return the Oracle 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 Oracle SQL parser instance created in constructor
-
getSecondaryParser
Return the Oracle PL/SQL parser instance with updated token list.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.
- Overrides:
getSecondaryParserin classAbstractSqlParser- Parameters:
context- parser context (not used, parser already created)tokens- source token list to parse- Returns:
- the Oracle PL/SQL parser instance created in constructor
-
tokenizeVendorSql
Call Oracle-specific tokenization logic.Delegates to dooraclesqltexttotokenlist which handles Oracle's specific keyword recognition, SQL*Plus commands, forward slash disambiguation, and token generation.
- Specified by:
tokenizeVendorSqlin classAbstractSqlParser
-
setupVendorParsersForExtraction
Setup Oracle parsers for raw statement extraction.Oracle uses dual parsers (SQL + PL/SQL), so we inject sqlcmds and update token lists for both parsers.
- Specified by:
setupVendorParsersForExtractionin classAbstractSqlParser
-
extractVendorRawStatements
Call Oracle-specific raw statement extraction logic.Delegates to dooraclegetrawsqlstatements which handles Oracle's statement delimiters (semicolon and forward slash).
- Specified by:
extractVendorRawStatementsin classAbstractSqlParser- Parameters:
builder- the result builder to populate with raw statements
-
performParsing
protected TStatementList performParsing(ParserContext context, TCustomParser parser, TCustomParser secondaryParser, TSourceTokenList tokens, TStatementList rawStatements) Perform full parsing of statements with syntax checking.This method orchestrates the parsing of all statements by:
- Using the raw statements passed from AbstractSqlParser.parse()
- Initializing SQL and PL/SQL parsers
- Creating global context and frame stack
- Looping through each raw statement
- Calling parsestatement() on each to build AST
- Handling error recovery for CREATE TABLE/INDEX
- Collecting syntax errors
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
- Specified by:
performParsingin classAbstractSqlParser- Parameters:
context- parser contextparser- main SQL parser (TParserOracleSql)secondaryParser- PL/SQL parser (TParserOraclePLSql)tokens- source token listrawStatements- raw statements already extracted (never null)- Returns:
- list of fully parsed statements with AST built
-
afterStatementParsed
Override to provide Oracle-specific post-processing after statement parsing.For Oracle, we check if the statement is PL/SQL and recursively find syntax errors in nested PL/SQL statements.
- Overrides:
afterStatementParsedin classAbstractSqlParser- Parameters:
stmt- the statement that was just parsed
-
performSemanticAnalysis
Perform Oracle-specific semantic analysis using TSQLResolver.This includes:
- Column-to-table resolution
- Dataflow analysis
- Reference resolution
- Scope resolution
- Overrides:
performSemanticAnalysisin classAbstractSqlParser- Parameters:
context- the parser contextstatements- the parsed statements
-
performInterpreter
Perform Oracle-specific AST interpretation/evaluation using TASTEvaluator.This executes simple SQL statements and evaluates expressions for static analysis and constant folding.
- Overrides:
performInterpreterin classAbstractSqlParser- Parameters:
context- the parser contextstatements- the parsed statements
-
toString
Copy syntax errors from a statement to our error list. Extracted from TGSqlParser.copyerrormsg().- Overrides:
toStringin classAbstractSqlParser
-