Skip to content

Commit 08f5db6

Browse files
author
Paultagoras
committed
This exposes the QuerySettings for folks to use, and also closes the response more cleanly
1 parent 9762e36 commit 08f5db6

File tree

2 files changed

+28
-5
lines changed

2 files changed

+28
-5
lines changed

jdbc-v2/src/main/java/com/clickhouse/jdbc/ResultSetImpl.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,12 @@ public boolean next() throws SQLException {
5757
public void close() throws SQLException {
5858
closed = true;
5959
if (reader != null) {
60+
try {
61+
reader.close();
62+
} catch (Exception e) {
63+
throw new SQLException(e);
64+
}
65+
6066
reader = null;
6167
}
6268

jdbc-v2/src/main/java/com/clickhouse/jdbc/StatementImpl.java

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import com.clickhouse.client.api.metrics.OperationMetrics;
55
import com.clickhouse.client.api.metrics.ServerMetrics;
66
import com.clickhouse.client.api.query.QueryResponse;
7+
import com.clickhouse.client.api.query.QuerySettings;
78
import org.slf4j.Logger;
89
import 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

Comments
 (0)