Class SQLUtils

java.lang.Object
com.clickhouse.client.api.sql.SQLUtils

public class SQLUtils extends Object
  • Constructor Details

    • SQLUtils

      public SQLUtils()
  • Method Details

    • enquoteLiteral

      public static String enquoteLiteral(String str)
      Escapes and quotes a string literal for use in SQL queries.
      Parameters:
      str - the string to be quoted, cannot be null
      Returns:
      the quoted and escaped string
      Throws:
      IllegalArgumentException - if the input string is null
    • enquoteIdentifier

      public static String enquoteIdentifier(String identifier, boolean quotesRequired)
      Escapes and quotes an SQL identifier (e.g., table or column name) by enclosing it in double quotes. Any existing double quotes in the identifier are escaped by doubling them.
      Parameters:
      identifier - the identifier to be quoted, cannot be null
      quotesRequired - if false, the identifier will only be quoted if it contains special characters
      Returns:
      the quoted and escaped identifier, or the original identifier if quoting is not required
      Throws:
      IllegalArgumentException - if the input identifier is null
    • enquoteIdentifier

      public static String enquoteIdentifier(String identifier)
      Escapes and quotes an SQL identifier, always adding quotes.
      Parameters:
      identifier - the identifier to be quoted, cannot be null
      Returns:
      the quoted and escaped identifier
      Throws:
      IllegalArgumentException - if the input identifier is null
      See Also:
    • isSimpleIdentifier

      public static boolean isSimpleIdentifier(String identifier)
      Checks if the given string is a valid simple SQL identifier using a compiled regex pattern. A simple identifier must match the pattern: ^[a-zA-Z][a-zA-Z0-9_]{0,127}$
      Parameters:
      identifier - the identifier to check
      Returns:
      true if the identifier is a valid simple SQL identifier, false otherwise
      Throws:
      IllegalArgumentException - if the input identifier is null
    • unquoteIdentifier

      public static String unquoteIdentifier(String str)
    • escapeSingleQuotes

      public static String escapeSingleQuotes(String x)