Package com.databend.jdbc

# Class StatementUtil

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

public class StatementUtil extends Object

## Constructor Summary

Constructors
Constructor
Description
`StatementUtil()`

## Method Summary

Modifier and Type
Method
Description
`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
`Optional<org.apache.commons.lang3.tuple.Pair<String,String>>`
`extractParamFromSetStatement(@NonNull String cleanSql, String sql)`
Extracts parameter from statement (eg: SET x=y)
`Map<Integer,Integer>`
`getParamMarketsPositions(String sql)`
Returns the positions of the params markers
`static boolean`
`isQuery(String cleanSql)`
Returns true if the statement is a query (eg: SELECT, SHOW).
`RawStatementWrapper`
`parseToRawStatementWrapper(String sql)`
Parse sql statement to a `RawStatementWrapper`.
`List<StatementInfoWrapper>`
`parseToStatementInfoWrappers(String sql)`
Parse the sql statement to a list of `StatementInfoWrapper`
`List<StatementInfoWrapper>`
`replaceParameterMarksWithValues(@NonNull Map<Integer,String> params, @NonNull RawStatementWrapper rawStatement)`
Returns a list of `StatementInfoWrapper` containing sql statements constructed with the `RawStatementWrapper` and the parameters provided
`static List<StatementInfoWrapper>`
`replaceParameterMarksWithValues(@NonNull Map<Integer,String> params, @NonNull String sql)`
Returns a list of `StatementInfoWrapper` containing sql statements constructed with the sql statement and the parameters provided

### Methods inherited from class java.lang.Object

`clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

## 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

### 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