Class MySqlSqlParser
- All Implemented Interfaces:
SqlParser
This parser handles MySQL-specific SQL syntax including:
- MySQL stored procedures and functions
- MySQL triggers
- Custom delimiter support (DELIMITER command)
- MySQL-specific DML/DDL
- Special operators and functions
- SOURCE command and \\. command
Design Notes:
- Extends
AbstractSqlParser - Can directly instantiate:
TLexerMysql,TParserMysqlSql - Uses single parser (no secondary parser like Oracle's PL/SQL)
- Delimiter character: ';' for SQL statements (configurable via DELIMITER command)
Usage Example:
// Get MySQL parser from factory
SqlParser parser = SqlParserFactory.get(EDbVendor.dbvmysql);
// Build context
ParserContext context = new ParserContext.Builder(EDbVendor.dbvmysql)
.sqlText("SELECT * FROM employees WHERE dept_id = 10")
.build();
// Parse
SqlParseResult result = parser.parse(context);
// Access statements
TStatementList statements = result.getSqlStatements();
- Since:
- 3.2.0.0
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class gudusoft.gsqlparser.parser.AbstractSqlParser
AbstractSqlParser.PreparedSqlReader -
Field Summary
FieldsModifier and TypeFieldDescriptionThe MySQL lexer used for tokenization (public for TGSqlParser.getFlexer())Fields 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 MySQL-specific raw statement extraction logic.protected TCustomLexergetLexer(ParserContext context) Return the MySQL lexer instance.protected TCustomParsergetParser(ParserContext context, TSourceTokenList tokens) Return the MySQL SQL parser instance with updated token list.protected TStatementListperformParsing(ParserContext context, TCustomParser parser, TCustomParser secondaryParser, TSourceTokenList tokens, TStatementList rawStatements) Perform full parsing of statements with syntax checking.protected voidSetup MySQL parser for raw statement extraction.protected voidCall MySQL-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
The MySQL lexer used for tokenization (public for TGSqlParser.getFlexer())
-
-
Constructor Details
-
MySqlSqlParser
public MySqlSqlParser()Construct MySQL SQL parser.Configures the parser for MySQL database with default delimiter: semicolon (;)
Following the original TGSqlParser pattern, the lexer and parser are created once in the constructor and reused for all parsing operations.
-
-
Method Details
-
getLexer
Return the MySQL 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 MySQL lexer instance created in constructor
-
getParser
Return the MySQL 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 MySQL SQL parser instance created in constructor
-
tokenizeVendorSql
Call MySQL-specific tokenization logic.Delegates to domysqltexttotokenlist which handles MySQL's specific keyword recognition, delimiter handling, and token generation.
- Specified by:
tokenizeVendorSqlin classAbstractSqlParser
-
setupVendorParsersForExtraction
Setup MySQL parser for raw statement extraction.MySQL uses a single parser, so we inject sqlcmds and update the token list for the main parser only.
- Specified by:
setupVendorParsersForExtractionin classAbstractSqlParser
-
extractVendorRawStatements
Call MySQL-specific raw statement extraction logic.Delegates to domysqlgetrawsqlstatements which handles MySQL's statement delimiters (semicolon by default, or custom delimiter via DELIMITER command).
- 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.
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).- Specified by:
performParsingin classAbstractSqlParser- Parameters:
context- parser contextparser- main SQL parser (TParserMysqlSql)secondaryParser- not used for MySQLtokens- source token listrawStatements- raw statements already extracted (never null)- Returns:
- list of fully parsed statements with AST built
-
toString
- Overrides:
toStringin classAbstractSqlParser
-