44import com .clickhouse .client .api .metrics .OperationMetrics ;
55import com .clickhouse .client .api .metrics .ServerMetrics ;
66import com .clickhouse .client .api .query .QueryResponse ;
7+ import com .clickhouse .client .api .query .QuerySettings ;
78import org .slf4j .Logger ;
89import org .slf4j .LoggerFactory ;
910
@@ -102,10 +103,15 @@ protected static String parseJdbcEscapeSyntax(String sql) {
102103 @ Override
103104 public ResultSet executeQuery (String sql ) throws SQLException {
104105 checkClosed ();
106+ return executeQuery (sql , new QuerySettings ());
107+ }
108+
109+ public ResultSet executeQuery (String sql , QuerySettings settings ) throws SQLException {
110+ checkClosed ();
105111
106112 try {
107113 sql = parseJdbcEscapeSyntax (sql );
108- QueryResponse response = connection .client .query (sql ).get (queryTimeout , TimeUnit .SECONDS );
114+ QueryResponse response = connection .client .query (sql , settings ).get (queryTimeout , TimeUnit .SECONDS );
109115 ClickHouseBinaryFormatReader reader = connection .client .newBinaryFormatReader (response );
110116 currentResultSet = new ResultSetImpl (response , reader );
111117 metrics = response .getMetrics ();
@@ -119,16 +125,22 @@ public ResultSet executeQuery(String sql) throws SQLException {
119125 @ Override
120126 public int executeUpdate (String sql ) throws SQLException {
121127 checkClosed ();
122-
128+ return executeUpdate (sql , new QuerySettings ());
129+ }
130+
131+ public int executeUpdate (String sql , QuerySettings settings ) throws SQLException {
132+ checkClosed ();
133+
123134 if (parseStatementType (sql ) == StatementType .SELECT ) {
124135 throw new SQLException ("executeUpdate() cannot be called with a SELECT statement" );
125136 }
126137
127138 try {
128139 sql = parseJdbcEscapeSyntax (sql );
129- QueryResponse response = connection .client .query (sql ).get (queryTimeout , TimeUnit .SECONDS );
140+ QueryResponse response = connection .client .query (sql , settings ).get (queryTimeout , TimeUnit .SECONDS );
130141 currentResultSet = null ;
131142 metrics = response .getMetrics ();
143+ response .close ();
132144 } catch (Exception e ) {
133145 throw new RuntimeException (e );
134146 }
@@ -209,14 +221,19 @@ public void setCursorName(String name) throws SQLException {
209221
210222 @ Override
211223 public boolean execute (String sql ) throws SQLException {
224+ checkClosed ();
225+ return execute (sql , new QuerySettings ());
226+ }
227+
228+ public boolean execute (String sql , QuerySettings settings ) throws SQLException {
212229 checkClosed ();
213230 StatementType type = parseStatementType (sql );
214231
215232 if (type == StatementType .SELECT ) {
216- executeQuery (sql );
233+ executeQuery (sql , settings );
217234 return true ;
218235 } else {
219- executeUpdate (sql );
236+ executeUpdate (sql , settings );
220237 return false ;
221238 }
222239 }
0 commit comments