Class Db2SqlParser

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

public class Db2SqlParser extends AbstractSqlParser
IBM DB2 SQL parser implementation.

This parser handles DB2-specific SQL syntax including:

  • DB2 SQL procedures and functions
  • DB2-specific triggers
  • DECLARE CURSOR and compound statements
  • DB2 echo commands treated as SQL*Plus commands
  • JDBC escape sequences
  • WITH isolation clauses

Design Notes:

Migrated from TGSqlParser:

  • dodb2sqltexttotokenlist() → tokenizeVendorSql()
  • dodb2getrawsqlstatements() → extractVendorRawStatements()
Since:
3.2.0.0
See Also:
  • Field Details

  • Constructor Details

    • Db2SqlParser

      public Db2SqlParser()
      Construct DB2 SQL parser.

      Configures the parser for IBM DB2 database with default delimiter: at-sign (@)

      Following the original TGSqlParser pattern, the lexer and parser are created once in the constructor and reused for all parsing operations.

      Note: DB2 uses '@' as the statement delimiter (not ';' like most databases). This is consistent with DB2 stored procedure conventions where @ marks the end of a procedure.

  • Method Details

    • getLexer

      protected TCustomLexer getLexer(ParserContext context)
      Return the DB2 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:
      getLexer in class AbstractSqlParser
      Parameters:
      context - parser context (not used, lexer already created)
      Returns:
      the DB2 lexer instance created in constructor
    • getParser

      protected TCustomParser getParser(ParserContext context, TSourceTokenList tokens)
      Return the DB2 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:
      getParser in class AbstractSqlParser
      Parameters:
      context - parser context (not used, parser already created)
      tokens - source token list to parse
      Returns:
      the DB2 SQL parser instance created in constructor
    • tokenizeVendorSql

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

      Delegates to dodb2sqltexttotokenlist which handles DB2's specific keyword recognition, JDBC escapes, and token generation.

      Specified by:
      tokenizeVendorSql in class AbstractSqlParser
    • setupVendorParsersForExtraction

      Setup DB2 parser for raw statement extraction.

      DB2 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 DB2-specific raw statement extraction logic.

      Delegates to dodb2getrawsqlstatements which handles DB2's statement boundaries, stored procedures, and compound blocks.

      Specified by:
      extractVendorRawStatements in class AbstractSqlParser
      Parameters:
      builder - result builder to populate
    • performParsing

      protected TStatementList performParsing(ParserContext context, TCustomParser parser, TCustomParser secondaryParser, TSourceTokenList tokens, TStatementList rawStatements)
      Perform full parsing on raw DB2 SQL statements.

      This method parses each raw statement into a complete parse tree, handling stored procedures, functions, triggers, and nested blocks.

      Specified by:
      performParsing in class AbstractSqlParser
      Parameters:
      context - parser context
      parser - main parser instance
      secondaryParser - secondary parser (null for DB2)
      tokens - source token list
      rawStatements - raw statements to parse
      Returns:
      list of parsed statements
    • toString

      public String toString()
      Overrides:
      toString in class AbstractSqlParser