Class StatementUtil

java.lang.Object
com.databend.jdbc.StatementUtil

public class StatementUtil extends Object
  • Constructor Details

    • StatementUtil

      public StatementUtil()
  • Method Details

    • isQuery

      public static boolean isQuery(String cleanSql)
      Returns true if the statement is a query (eg: SELECT, SHOW).
      Parameters:
      cleanSql - the clean sql (sql statement without comments)
      Returns:
      true if the statement is a query (eg: SELECT, SHOW).
    • extractParamFromSetStatement

      public Optional<org.apache.commons.lang3.tuple.Pair<String,String>> extractParamFromSetStatement(@NonNull @NonNull String cleanSql, String sql)
      Extracts parameter from statement (eg: SET x=y)
      Parameters:
      cleanSql - the clean version of the sql (sql statement without comments)
      sql - the sql statement
      Returns:
      an optional parameter represented with a pair of key/value
    • extractColumnTypes

      public static Map<Integer,String> extractColumnTypes(String sql)
      This method is used to extract column types from a SQL statement. It parses the SQL statement and finds the column types defined in the first pair of parentheses. The column types are then stored in a Map where the key is the index of the column in the SQL statement and the value is the type of the column.
      Parameters:
      sql - The SQL statement from which to extract column types.
      Returns:
      A Map where the key is the index of the column and the value is the type of the column.
    • parseToStatementInfoWrappers

      public List<StatementInfoWrapper> parseToStatementInfoWrappers(String sql)
      Parse the sql statement to a list of StatementInfoWrapper
      Parameters:
      sql - the sql statement
      Returns:
      a list of StatementInfoWrapper
    • parseToRawStatementWrapper

      public RawStatementWrapper parseToRawStatementWrapper(String sql)
      Parse sql statement to a RawStatementWrapper. The method construct the RawStatementWrapper by splitting it in a list of sub-statements (supports multistatements)
      Parameters:
      sql - the sql statement
      Returns:
      a list of StatementInfoWrapper
    • getParamMarketsPositions

      public Map<Integer,Integer> getParamMarketsPositions(String sql)
      Returns the positions of the params markers
      Parameters:
      sql - the sql statement
      Returns:
      the positions of the params markers
    • extractDbNameAndTableNamePairFromCleanQuery

      public org.apache.commons.lang3.tuple.Pair<Optional<String>,Optional<String>> extractDbNameAndTableNamePairFromCleanQuery(String cleanSql)
      Extract the database name and the table name from the cleaned sql query
      Parameters:
      cleanSql - the clean sql query
      Returns:
      the database name and the table name from the sql query as a pair
    • replaceParameterMarksWithValues

      public static List<StatementInfoWrapper> replaceParameterMarksWithValues(@NonNull @NonNull Map<Integer,String> params, @NonNull @NonNull String sql)
      Returns a list of StatementInfoWrapper containing sql statements constructed with the sql statement and the parameters provided
      Parameters:
      params - the parameters
      sql - the sql statement
      Returns:
      a list of sql statements containing the provided parameters
    • replaceParameterMarksWithValues

      public List<StatementInfoWrapper> replaceParameterMarksWithValues(@NonNull @NonNull Map<Integer,String> params, @NonNull @NonNull RawStatementWrapper rawStatement)
      Returns a list of StatementInfoWrapper containing sql statements constructed with the RawStatementWrapper and the parameters provided
      Parameters:
      params - the parameters
      rawStatement - the rawStatement
      Returns:
      a list of sql statements containing the provided parameters