Skip to content

Commit f880b09

Browse files
authored
Merge pull request #2013 from ClickHouse/datagrip-issues
Updating to address some seen issues/bugs in DataGrip testing
2 parents 2192336 + 2a2545b commit f880b09

File tree

5 files changed

+114
-82
lines changed

5 files changed

+114
-82
lines changed

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

Lines changed: 21 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -106,13 +106,13 @@ public JdbcConfiguration getJdbcConfig() {
106106
@Override
107107
public Statement createStatement() throws SQLException {
108108
checkOpen();
109-
return new StatementImpl(this);
109+
return createStatement(ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY, ResultSet.CLOSE_CURSORS_AT_COMMIT);
110110
}
111111

112112
@Override
113113
public PreparedStatement prepareStatement(String sql) throws SQLException {
114114
checkOpen();
115-
return new PreparedStatementImpl(this, sql);
115+
return prepareStatement(sql, ResultSet.TYPE_FORWARD_ONLY, ResultSet.CONCUR_READ_ONLY, ResultSet.CLOSE_CURSORS_AT_COMMIT);
116116
}
117117

118118
@Override
@@ -231,14 +231,13 @@ public void clearWarnings() throws SQLException {
231231
@Override
232232
public Statement createStatement(int resultSetType, int resultSetConcurrency) throws SQLException {
233233
checkOpen();
234-
//TODO: Should this be a silent ignore?
235-
throw new SQLFeatureNotSupportedException("Statement with resultSetType and resultSetConcurrency override not supported", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED);
234+
return createStatement(resultSetType, resultSetConcurrency, ResultSet.CLOSE_CURSORS_AT_COMMIT);
236235
}
237236

238237
@Override
239238
public PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency) throws SQLException {
240239
checkOpen();
241-
throw new SQLFeatureNotSupportedException("PreparedStatement with resultSetType and resultSetConcurrency override not supported", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED);
240+
return prepareStatement(sql, resultSetType, resultSetConcurrency, ResultSet.CLOSE_CURSORS_AT_COMMIT);
242241
}
243242

244243
@Override
@@ -300,15 +299,13 @@ public void releaseSavepoint(Savepoint savepoint) throws SQLException {
300299
@Override
301300
public Statement createStatement(int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException {
302301
checkOpen();
303-
//TODO: Should this be a silent ignore?
304-
throw new SQLFeatureNotSupportedException("Statement with resultSetType, resultSetConcurrency, and resultSetHoldability override not supported", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED);
302+
return new StatementImpl(this);
305303
}
306304

307305
@Override
308306
public PreparedStatement prepareStatement(String sql, int resultSetType, int resultSetConcurrency, int resultSetHoldability) throws SQLException {
309307
checkOpen();
310-
//TODO: Should this be a silent ignore?
311-
throw new SQLFeatureNotSupportedException("PreparedStatement with resultSetType, resultSetConcurrency, and resultSetHoldability override not supported", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED);
308+
return new PreparedStatementImpl(this, sql);
312309
}
313310

314311
@Override
@@ -321,21 +318,33 @@ public CallableStatement prepareCall(String sql, int resultSetType, int resultSe
321318
public PreparedStatement prepareStatement(String sql, int autoGeneratedKeys) throws SQLException {
322319
checkOpen();
323320
//TODO: Should this be supported?
324-
throw new SQLFeatureNotSupportedException("prepareStatement(String sql, int autoGeneratedKeys) not supported", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED);
321+
if (!config.isIgnoreUnsupportedRequests()) {
322+
throw new SQLFeatureNotSupportedException("prepareStatement(String sql, int autoGeneratedKeys) not supported", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED);
323+
} else {
324+
return prepareStatement(sql);
325+
}
325326
}
326327

327328
@Override
328329
public PreparedStatement prepareStatement(String sql, int[] columnIndexes) throws SQLException {
329330
checkOpen();
330331
//TODO: Should this be supported?
331-
throw new SQLFeatureNotSupportedException("prepareStatement(String sql, int[] columnIndexes) not supported", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED);
332+
if (!config.isIgnoreUnsupportedRequests()) {
333+
throw new SQLFeatureNotSupportedException("prepareStatement(String sql, int[] columnIndexes) not supported", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED);
334+
} else {
335+
return prepareStatement(sql);
336+
}
332337
}
333338

334339
@Override
335340
public PreparedStatement prepareStatement(String sql, String[] columnNames) throws SQLException {
336341
checkOpen();
337342
//TODO: Should this be supported?
338-
throw new SQLFeatureNotSupportedException("prepareStatement(String sql, String[] columnNames) not supported", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED);
343+
if (!config.isIgnoreUnsupportedRequests()) {
344+
throw new SQLFeatureNotSupportedException("prepareStatement(String sql, String[] columnNames) not supported", ExceptionUtils.SQL_STATE_FEATURE_NOT_SUPPORTED);
345+
} else {
346+
return prepareStatement(sql);
347+
}
339348
}
340349

341350
@Override

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

Lines changed: 35 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -30,10 +30,10 @@ public class ResultSetImpl implements ResultSet, JdbcV2Wrapper {
3030
protected ClickHouseBinaryFormatReader reader;
3131
private QueryResponse response;
3232
private boolean closed;
33-
private final Statement parentStatement;
33+
private final StatementImpl parentStatement;
3434
private boolean wasNull;
3535

36-
public ResultSetImpl(Statement parentStatement, QueryResponse response, ClickHouseBinaryFormatReader reader) {
36+
public ResultSetImpl(StatementImpl parentStatement, QueryResponse response, ClickHouseBinaryFormatReader reader) {
3737
this.parentStatement = parentStatement;
3838
this.response = response;
3939
this.reader = reader;
@@ -102,7 +102,7 @@ public String getString(int columnIndex) throws SQLException {
102102
return null;
103103
}
104104
} catch (Exception e) {
105-
throw ExceptionUtils.toSqlState(e);
105+
throw ExceptionUtils.toSqlState(String.format("SQL: [%s]; Method: getString(%s)", parentStatement.getLastSql(), columnIndex), e);
106106
}
107107
}
108108

@@ -118,7 +118,7 @@ public boolean getBoolean(int columnIndex) throws SQLException {
118118
return false;
119119
}
120120
} catch (Exception e) {
121-
throw ExceptionUtils.toSqlState(e);
121+
throw ExceptionUtils.toSqlState(String.format("SQL: [%s]; Method: getBoolean(%s)", parentStatement.getLastSql(), columnIndex), e);
122122
}
123123
}
124124

@@ -134,7 +134,7 @@ public byte getByte(int columnIndex) throws SQLException {
134134
return 0;
135135
}
136136
} catch (Exception e) {
137-
throw ExceptionUtils.toSqlState(e);
137+
throw ExceptionUtils.toSqlState(String.format("SQL: [%s]; Method: getByte(%s)", parentStatement.getLastSql(), columnIndex), e);
138138
}
139139
}
140140

@@ -150,7 +150,7 @@ public short getShort(int columnIndex) throws SQLException {
150150
return 0;
151151
}
152152
} catch (Exception e) {
153-
throw ExceptionUtils.toSqlState(e);
153+
throw ExceptionUtils.toSqlState(String.format("SQL: [%s]; Method: getShort(%s)", parentStatement.getLastSql(), columnIndex), e);
154154
}
155155
}
156156

@@ -166,7 +166,7 @@ public int getInt(int columnIndex) throws SQLException {
166166
return 0;
167167
}
168168
} catch (Exception e) {
169-
throw ExceptionUtils.toSqlState(e);
169+
throw ExceptionUtils.toSqlState(String.format("SQL: [%s]; Method: getInt(%s)", parentStatement.getLastSql(), columnIndex), e);
170170
}
171171
}
172172

@@ -182,7 +182,7 @@ public long getLong(int columnIndex) throws SQLException {
182182
return 0;
183183
}
184184
} catch (Exception e) {
185-
throw ExceptionUtils.toSqlState(e);
185+
throw ExceptionUtils.toSqlState(String.format("SQL: [%s]; Method: getLong(%s)", parentStatement.getLastSql(), columnIndex), e);
186186
}
187187
}
188188

@@ -198,7 +198,7 @@ public float getFloat(int columnIndex) throws SQLException {
198198
return 0;
199199
}
200200
} catch (Exception e) {
201-
throw ExceptionUtils.toSqlState(e);
201+
throw ExceptionUtils.toSqlState(String.format("SQL: [%s]; Method: getFloat(%s)", parentStatement.getLastSql(), columnIndex), e);
202202
}
203203
}
204204

@@ -214,7 +214,7 @@ public double getDouble(int columnIndex) throws SQLException {
214214
return 0;
215215
}
216216
} catch (Exception e) {
217-
throw ExceptionUtils.toSqlState(e);
217+
throw ExceptionUtils.toSqlState(String.format("SQL: [%s]; Method: getDouble(%s)", parentStatement.getLastSql(), columnIndex), e);
218218
}
219219
}
220220

@@ -230,7 +230,7 @@ public BigDecimal getBigDecimal(int columnIndex, int scale) throws SQLException
230230
return null;
231231
}
232232
} catch (Exception e) {
233-
throw ExceptionUtils.toSqlState(e);
233+
throw ExceptionUtils.toSqlState(String.format("SQL: [%s]; Method: getBigDecimal(%s)", parentStatement.getLastSql(), columnIndex), e);
234234
}
235235
}
236236

@@ -246,7 +246,7 @@ public byte[] getBytes(int columnIndex) throws SQLException {
246246
return null;
247247
}
248248
} catch (Exception e) {
249-
throw ExceptionUtils.toSqlState(e);
249+
throw ExceptionUtils.toSqlState(String.format("SQL: [%s]; Method: getBytes(%s)", parentStatement.getLastSql(), columnIndex), e);
250250
}
251251
}
252252

@@ -264,7 +264,7 @@ public Date getDate(int columnIndex) throws SQLException {
264264
wasNull = false;
265265
return Date.valueOf(localDate);
266266
} catch (Exception e) {
267-
throw ExceptionUtils.toSqlState(e);
267+
throw ExceptionUtils.toSqlState(String.format("SQL: [%s]; Method: getDate(%s)", parentStatement.getLastSql(), columnIndex), e);
268268
}
269269
}
270270

@@ -281,7 +281,7 @@ public Time getTime(int columnIndex) throws SQLException {
281281
wasNull = false;
282282
return Time.valueOf(localDateTime.toLocalTime());
283283
} catch (Exception e) {
284-
throw ExceptionUtils.toSqlState(e);
284+
throw ExceptionUtils.toSqlState(String.format("SQL: [%s]; Method: getTime(%s)", parentStatement.getLastSql(), columnIndex), e);
285285
}
286286
}
287287

@@ -298,7 +298,7 @@ public Timestamp getTimestamp(int columnIndex) throws SQLException {
298298
wasNull = false;
299299
return Timestamp.valueOf(localDateTime);
300300
} catch (Exception e) {
301-
throw ExceptionUtils.toSqlState(e);
301+
throw ExceptionUtils.toSqlState(String.format("SQL: [%s]; Method: getTimestamp(%s)", parentStatement.getLastSql(), columnIndex), e);
302302
}
303303
}
304304

@@ -334,7 +334,7 @@ public String getString(String columnLabel) throws SQLException {
334334
return null;
335335
}
336336
} catch (Exception e) {
337-
throw ExceptionUtils.toSqlState(e);
337+
throw ExceptionUtils.toSqlState(String.format("SQL: [%s]; Method: getString(%s)", parentStatement.getLastSql(), columnLabel), e);
338338
}
339339
}
340340

@@ -350,7 +350,7 @@ public boolean getBoolean(String columnLabel) throws SQLException {
350350
return false;
351351
}
352352
} catch (Exception e) {
353-
throw ExceptionUtils.toSqlState(e);
353+
throw ExceptionUtils.toSqlState(String.format("SQL: [%s]; Method: getBoolean(%s)", parentStatement.getLastSql(), columnLabel), e);
354354
}
355355
}
356356

@@ -366,7 +366,7 @@ public byte getByte(String columnLabel) throws SQLException {
366366
return 0;
367367
}
368368
} catch (Exception e) {
369-
throw ExceptionUtils.toSqlState(e);
369+
throw ExceptionUtils.toSqlState(String.format("SQL: [%s]; Method: getByte(%s)", parentStatement.getLastSql(), columnLabel), e);
370370
}
371371
}
372372

@@ -382,7 +382,7 @@ public short getShort(String columnLabel) throws SQLException {
382382
return 0;
383383
}
384384
} catch (Exception e) {
385-
throw ExceptionUtils.toSqlState(e);
385+
throw ExceptionUtils.toSqlState(String.format("SQL: [%s]; Method: getShort(%s)", parentStatement.getLastSql(), columnLabel), e);
386386
}
387387
}
388388

@@ -398,7 +398,7 @@ public int getInt(String columnLabel) throws SQLException {
398398
return 0;
399399
}
400400
} catch (Exception e) {
401-
throw ExceptionUtils.toSqlState(e);
401+
throw ExceptionUtils.toSqlState(String.format("SQL: [%s]; Method: getInt(%s)", parentStatement.getLastSql(), columnLabel), e);
402402
}
403403
}
404404

@@ -414,7 +414,7 @@ public long getLong(String columnLabel) throws SQLException {
414414
return 0;
415415
}
416416
} catch (Exception e) {
417-
throw ExceptionUtils.toSqlState(e);
417+
throw ExceptionUtils.toSqlState(String.format("SQL: [%s]; Method: getLong(%s)", parentStatement.getLastSql(), columnLabel), e);
418418
}
419419
}
420420

@@ -430,7 +430,7 @@ public float getFloat(String columnLabel) throws SQLException {
430430
return 0;
431431
}
432432
} catch (Exception e) {
433-
throw ExceptionUtils.toSqlState(e);
433+
throw ExceptionUtils.toSqlState(String.format("SQL: [%s]; Method: getFloat(%s)", parentStatement.getLastSql(), columnLabel), e);
434434
}
435435
}
436436

@@ -446,7 +446,7 @@ public double getDouble(String columnLabel) throws SQLException {
446446
return 0;
447447
}
448448
} catch (Exception e) {
449-
throw ExceptionUtils.toSqlState(e);
449+
throw ExceptionUtils.toSqlState(String.format("SQL: [%s]; Method: getDouble(%s)", parentStatement.getLastSql(), columnLabel), e);
450450
}
451451
}
452452

@@ -462,7 +462,7 @@ public BigDecimal getBigDecimal(String columnLabel, int scale) throws SQLExcepti
462462
return null;
463463
}
464464
} catch (Exception e) {
465-
throw ExceptionUtils.toSqlState(e);
465+
throw ExceptionUtils.toSqlState(String.format("SQL: [%s]; Method: getBigDecimal(%s)", parentStatement.getLastSql(), columnLabel), e);
466466
}
467467
}
468468

@@ -478,7 +478,7 @@ public byte[] getBytes(String columnLabel) throws SQLException {
478478
return null;
479479
}
480480
} catch (Exception e) {
481-
throw ExceptionUtils.toSqlState(e);
481+
throw ExceptionUtils.toSqlState(String.format("SQL: [%s]; Method: getBytes(%s)", parentStatement.getLastSql(), columnLabel), e);
482482
}
483483
}
484484

@@ -496,7 +496,7 @@ public Date getDate(String columnLabel) throws SQLException {
496496
wasNull = false;
497497
return Date.valueOf(localDate);
498498
} catch (Exception e) {
499-
throw ExceptionUtils.toSqlState(e);
499+
throw ExceptionUtils.toSqlState(String.format("SQL: [%s]; Method: getDate(%s)", parentStatement.getLastSql(), columnLabel), e);
500500
}
501501
}
502502

@@ -513,7 +513,7 @@ public Time getTime(String columnLabel) throws SQLException {
513513
wasNull = false;
514514
return Time.valueOf(localDateTime.toLocalTime());
515515
} catch (Exception e) {
516-
throw ExceptionUtils.toSqlState(e);
516+
throw ExceptionUtils.toSqlState(String.format("SQL: [%s]; Method: getTime(%s)", parentStatement.getLastSql(), columnLabel), e);
517517
}
518518
}
519519

@@ -530,7 +530,7 @@ public Timestamp getTimestamp(String columnLabel) throws SQLException {
530530
wasNull = false;
531531
return Timestamp.valueOf(localDateTime);
532532
} catch (Exception e) {
533-
throw ExceptionUtils.toSqlState(e);
533+
throw ExceptionUtils.toSqlState(String.format("SQL: [%s]; Method: getTimestamp(%s)", parentStatement.getLastSql(), columnLabel), e);
534534
}
535535
}
536536

@@ -589,7 +589,7 @@ public Object getObject(int columnIndex) throws SQLException {
589589
return null;
590590
}
591591
} catch (Exception e) {
592-
throw ExceptionUtils.toSqlState(e);
592+
throw ExceptionUtils.toSqlState(String.format("SQL: [%s]; Method: getObject(%s)", parentStatement.getLastSql(), columnIndex), e);
593593
}
594594
}
595595

@@ -605,7 +605,7 @@ public Object getObject(String columnLabel) throws SQLException {
605605
return null;
606606
}
607607
} catch (Exception e) {
608-
throw ExceptionUtils.toSqlState(e);
608+
throw ExceptionUtils.toSqlState(String.format("SQL: [%s]; Method: getObject(%s)", parentStatement.getLastSql(), columnLabel), e);
609609
}
610610
}
611611

@@ -615,7 +615,7 @@ public int findColumn(String columnLabel) throws SQLException {
615615
try {
616616
return reader.getSchema().getColumnByName(columnLabel).getColumnIndex();
617617
} catch (Exception e) {
618-
throw ExceptionUtils.toSqlState(e);
618+
throw ExceptionUtils.toSqlState(String.format("SQL: [%s]; Method: findColumn(%s)", parentStatement.getLastSql(), columnLabel), e);
619619
}
620620
}
621621

@@ -643,7 +643,7 @@ public BigDecimal getBigDecimal(int columnIndex) throws SQLException {
643643
return null;
644644
}
645645
} catch (Exception e) {
646-
throw ExceptionUtils.toSqlState(e);
646+
throw ExceptionUtils.toSqlState(String.format("SQL: [%s]; Method: getBigDecimal(%s)", parentStatement.getLastSql(), columnIndex), e);
647647
}
648648
}
649649

@@ -659,7 +659,7 @@ public BigDecimal getBigDecimal(String columnLabel) throws SQLException {
659659
return null;
660660
}
661661
} catch (Exception e) {
662-
throw ExceptionUtils.toSqlState(e);
662+
throw ExceptionUtils.toSqlState(String.format("SQL: [%s]; Method: getBigDecimal(%s)", parentStatement.getLastSql(), columnLabel), e);
663663
}
664664
}
665665

@@ -1088,7 +1088,7 @@ public java.sql.Array getArray(int columnIndex) throws SQLException {
10881088
@Override
10891089
public Object getObject(String columnLabel, Map<String, Class<?>> map) throws SQLException {
10901090
checkClosed();
1091-
return null;
1091+
return getObject(columnLabel);
10921092
}
10931093

10941094
@Override
@@ -1116,7 +1116,7 @@ public java.sql.Array getArray(String columnLabel) throws SQLException {
11161116
ClickHouseColumn column = reader.getSchema().getColumnByName(columnLabel);
11171117
return new Array(reader.getList(columnLabel), JdbcUtils.convertToSqlType(column.getArrayBaseColumn().getDataType()));
11181118
} catch (Exception e) {
1119-
throw ExceptionUtils.toSqlState(e);
1119+
throw ExceptionUtils.toSqlState(String.format("SQL: [%s]; Method: getArray(%s)", parentStatement.getLastSql(), columnLabel), e);
11201120
}
11211121
}
11221122

0 commit comments

Comments
 (0)