Class SqlCommentParser


  • public class SqlCommentParser
    extends Object
    Utility class for parsing out comments from SQL strings
    • Constructor Detail

      • SqlCommentParser

        public SqlCommentParser()
    • Method Detail

      • forEachNonCommentChar

        public static void forEachNonCommentChar​(String sql,
                                                 SqlCommentParser.SqlCharConsumer consumer)
        Iterates over each character in the SQL string while keeping track of comment, string literal, and identifier state. Each character that is not part of a comment calls the consumer with the current state and character. Emits a ' ' character after each comment to avoid token fusion.
        Parameters:
        sql - the SQL string to parse
        consumer - called for each visible character with its parsing state
      • stripCommentsAndWhitespaces

        public static String stripCommentsAndWhitespaces​(String sql)
        Removes all comments and extra whitespace from the SQL string.
        Parameters:
        sql - the SQL string to remove comments and extra whitespace from
        Returns:
        the SQL string with all comments and extra whitespace removed