Class MssqlSqlParser

Object
gudusoft.gsqlparser.parser.AbstractSqlParser
gudusoft.gsqlparser.parser.MssqlSqlParser
All Implemented Interfaces:
SqlParser

public class MssqlSqlParser extends AbstractSqlParser
Microsoft SQL Server database SQL parser implementation.

This parser handles SQL Server-specific SQL syntax including:

  • T-SQL blocks (stored procedures, functions, triggers)
  • BEGIN/END blocks
  • TRY/CATCH error handling
  • GO batch separator
  • SQL Server-specific DML/DDL (MERGE, OPENROWSET, etc.)
  • Special token handling (LOCK TABLE, COPY INTO, etc.)

Design Notes:

Usage Example:

 // Get SQL Server parser from factory
 SqlParser parser = SqlParserFactory.get(EDbVendor.dbvmssql);

 // Build context
 ParserContext context = new ParserContext.Builder(EDbVendor.dbvmssql)
     .sqlText("SELECT * FROM Employees WHERE DepartmentID = 10")
     .build();

 // Parse
 SqlParseResult result = parser.parse(context);

 // Access statements
 TStatementList statements = result.getSqlStatements();
 
Since:
3.2.0.0
See Also:
  • Field Details

  • Constructor Details

    • MssqlSqlParser

      public MssqlSqlParser()
      Construct SQL Server SQL parser.

      Configures the parser for SQL Server 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.

  • Method Details

    • getLexer

      protected TCustomLexer getLexer(ParserContext context)
      Return the SQL Server lexer instance.
      Specified by:
      getLexer in class AbstractSqlParser
      Parameters:
      context - the parser context
      Returns:
      configured lexer instance (never null)
    • getParser

      protected TCustomParser getParser(ParserContext context, TSourceTokenList tokens)
      Return the SQL Server SQL parser instance with updated token list.
      Specified by:
      getParser in class AbstractSqlParser
      Parameters:
      context - the parser context
      tokens - the source token list
      Returns:
      configured parser instance (never null)
    • tokenizeVendorSql

      protected void tokenizeVendorSql()
      Call MSSQL-specific tokenization logic.

      Delegates to domssqlsqltexttotokenlist which handles SQL Server's specific keyword recognition, bracket identifiers, and token generation.

      Specified by:
      tokenizeVendorSql in class AbstractSqlParser
    • setupVendorParsersForExtraction

      Setup MSSQL parser for raw statement extraction.

      MSSQL uses a single parser, so we inject sqlcmds and update the token list for the main parser only.

      Specified by:
      setupVendorParsersForExtraction in class AbstractSqlParser
    • extractVendorRawStatements

      Call MSSQL-specific raw statement extraction logic.

      Delegates to domssqlgetrawsqlstatements which handles SQL Server's statement delimiters (semicolon and GO command).

      Specified by:
      extractVendorRawStatements in class AbstractSqlParser
      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.

      Specified by:
      performParsing in class AbstractSqlParser
      Parameters:
      context - the parser context
      parser - the main parser instance
      secondaryParser - secondary parser (may be null)
      tokens - the source token list
      rawStatements - raw statements already extracted (never null)
      Returns:
      statement list with parsed AST (never null)
    • performSemanticAnalysis

      protected void performSemanticAnalysis(ParserContext context, TStatementList statements)
      Perform SQL Server-specific semantic analysis.

      When called via delegation from TGSqlParser (context.getGsqlparser() != null), semantic analysis is skipped here and handled by TGSqlParser.doDelegatedParse() to ensure resolver2 is stored in TGSqlParser where tests expect to find it.

      When called directly on MssqlSqlParser, uses TBaseType flags to determine which resolver to use:

      • TBaseType.isEnableResolver2() -> use TSQLResolver2
      • TBaseType.isEnableResolver() -> use TSQLResolver
      Overrides:
      performSemanticAnalysis in class AbstractSqlParser
      Parameters:
      context - the parser context
      statements - the parsed statements (mutable)
    • performInterpreter

      protected void performInterpreter(ParserContext context, TStatementList statements)
      Perform interpretation/evaluation on parsed statements.
      Overrides:
      performInterpreter in class AbstractSqlParser
      Parameters:
      context - the parser context
      statements - the parsed statements (mutable)