Skip to content

Commit e0bdc8b

Browse files
committed
added more tests
1 parent 0e690c8 commit e0bdc8b

File tree

3 files changed

+81
-3
lines changed

3 files changed

+81
-3
lines changed

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

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,18 @@
1313
*/
1414
public enum DriverProperties {
1515

16-
IGNORE_UNSUPPORTED_VALUES("jdbc_ignore_unsupported_values", ""),
17-
SCHEMA_TERM("jdbc_schema_term", ""),
16+
/**
17+
* Indicates if driver should ignore unsupported values and methods.
18+
* JDBC allows throwing SQLException for unsupported values and methods.
19+
* But driver can ignore them and continue execution. Driver will do no operation in such case.
20+
*/
21+
IGNORE_UNSUPPORTED_VALUES("jdbc_ignore_unsupported_values", "false"),
22+
23+
/**
24+
* Schema term to be used in the connection URL. Only `schema` is supported right now.
25+
*/
26+
SCHEMA_TERM("jdbc_schema_term", "schema"),
27+
1828
/**
1929
* Indicates if driver should create a secure connection over SSL/TLS
2030
*/

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,7 @@ public void clearWarnings() throws SQLException {
326326

327327
@Override
328328
public void setCursorName(String name) throws SQLException {
329+
featureManager.unsupportedFeatureThrow("setCursorName(String)", true);
329330
ensureOpen();
330331
}
331332

@@ -623,16 +624,19 @@ public long executeLargeUpdate(String sql) throws SQLException {
623624

624625
@Override
625626
public long executeLargeUpdate(String sql, int autoGeneratedKeys) throws SQLException {
627+
featureManager.unsupportedFeatureThrow("executeLargeUpdate(String, int)", autoGeneratedKeys != Statement.NO_GENERATED_KEYS);
626628
return executeLargeUpdate(sql);
627629
}
628630

629631
@Override
630632
public long executeLargeUpdate(String sql, int[] columnIndexes) throws SQLException {
633+
featureManager.unsupportedFeatureThrow("executeLargeUpdate(String, int[])");
631634
return executeLargeUpdate(sql);
632635
}
633636

634637
@Override
635638
public long executeLargeUpdate(String sql, String[] columnNames) throws SQLException {
639+
featureManager.unsupportedFeatureThrow("executeLargeUpdate(String, String[])");
636640
return executeLargeUpdate(sql);
637641
}
638642

jdbc-v2/src/test/java/com/clickhouse/jdbc/StatementTest.java

Lines changed: 65 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1109,7 +1109,7 @@ public void testExecute() throws Exception {
11091109
}
11101110

11111111
@Test(groups = {"integration"})
1112-
public void setConnectionSchema() throws Exception {
1112+
public void testSetConnectionSchema() throws Exception {
11131113
String db1 = getDatabase() + "_schema1";
11141114
String db2 = getDatabase() + "_schema2";
11151115
try (Connection conn = getJdbcConnection(); Statement stmt = conn.createStatement()) {
@@ -1129,6 +1129,70 @@ public void setConnectionSchema() throws Exception {
11291129
}
11301130
}
11311131

1132+
@Test(groups = {"integration"}, dataProvider = "testUnsupportedOperationsDP")
1133+
public void testUnsupportedOperations(Properties props, boolean shouldThrow) throws Exception {
1134+
try (Connection conn = getJdbcConnection(props); Statement stmt = conn.createStatement()) {
1135+
List<Assert.ThrowingRunnable> unsupportedOperations = Arrays.asList(
1136+
() -> stmt.execute("SELECT 1", Statement.RETURN_GENERATED_KEYS),
1137+
() -> stmt.execute("SELECT 1", new int[] {1}),
1138+
() -> stmt.execute("SELECT 1", new String[] {"1"}),
1139+
() -> stmt.executeUpdate("CREATE TABLE IF NOT EXISTS test_unsupported_01 (id Int32) Engine MergeTree ORDER BY ()", Statement.RETURN_GENERATED_KEYS),
1140+
() -> stmt.executeUpdate("CREATE TABLE IF NOT EXISTS test_unsupported_02 (id Int32) Engine MergeTree ORDER BY ()", new int[] {1}),
1141+
() -> stmt.executeUpdate("CREATE TABLE IF NOT EXISTS test_unsupported_03 (id Int32) Engine MergeTree ORDER BY ()", new String[] {"1"}),
1142+
() -> stmt.executeLargeUpdate("CREATE TABLE IF NOT EXISTS test_unsupported_01 (id Int32) Engine MergeTree ORDER BY ()", Statement.RETURN_GENERATED_KEYS),
1143+
() -> stmt.executeLargeUpdate("CREATE TABLE IF NOT EXISTS test_unsupported_02 (id Int32) Engine MergeTree ORDER BY ()", new int[] {1}),
1144+
() -> stmt.executeLargeUpdate("CREATE TABLE IF NOT EXISTS test_unsupported_03 (id Int32) Engine MergeTree ORDER BY ()", new String[] {"1"}),
1145+
() -> stmt.setCursorName("CURSOR_NAME_IGNORED")
1146+
);
1147+
1148+
stmt.execute("SELECT 1", Statement.NO_GENERATED_KEYS); // supported
1149+
stmt.executeUpdate("CREATE TABLE IF NOT EXISTS test_unsupported_04 (id Int32) Engine MergeTree ORDER BY ()", Statement.NO_GENERATED_KEYS); // supported
1150+
stmt.executeLargeUpdate("CREATE TABLE IF NOT EXISTS test_unsupported_04 (id Int32) Engine MergeTree ORDER BY ()", Statement.NO_GENERATED_KEYS); // supported
1151+
1152+
assertNull(stmt.getGeneratedKeys());
1153+
1154+
1155+
for (Assert.ThrowingRunnable op : unsupportedOperations) {
1156+
if (shouldThrow) {
1157+
assertThrows(SQLException.class, op);
1158+
} else {
1159+
try {
1160+
op.run();
1161+
} catch (Throwable e) {
1162+
fail(e.getMessage(), e);
1163+
}
1164+
}
1165+
}
1166+
}
1167+
}
1168+
1169+
@DataProvider(name = "testUnsupportedOperationsDP")
1170+
public static Object[][] testUnsupportedOperationsDP() {
1171+
Properties props1 = new Properties();
1172+
Properties props2 = new Properties();
1173+
props2.put(DriverProperties.IGNORE_UNSUPPORTED_VALUES.getKey(), "true");
1174+
Properties props3 = new Properties();
1175+
props3.put(DriverProperties.IGNORE_UNSUPPORTED_VALUES.getKey(), "false");
1176+
return new Object[][] {
1177+
{props1, true},
1178+
{props2, false},
1179+
{props3, true}
1180+
};
1181+
}
1182+
1183+
@Test(groups = {"integration"})
1184+
public void testSetFetchSize() throws Exception {
1185+
try (Connection conn = getJdbcConnection()) {
1186+
try (Statement stmt = conn.createStatement()) {
1187+
stmt.setFetchSize(10000);
1188+
Assert.assertEquals(stmt.getFetchSize(), 10000);
1189+
stmt.setFetchSize(0);
1190+
Assert.assertEquals(stmt.getFetchSize(), 0);
1191+
Assert.assertThrows(SQLException.class, () -> stmt.setFetchSize(-1));
1192+
}
1193+
}
1194+
}
1195+
11321196
private static String getDBName(Statement stmt) throws SQLException {
11331197
try (ResultSet rs = stmt.executeQuery("SELECT database()")) {
11341198
rs.next();

0 commit comments

Comments
 (0)