Skip to content

Commit a113328

Browse files
committed
Updated tests for PreparedStatement
1 parent 6cd1bf6 commit a113328

File tree

2 files changed

+12
-43
lines changed

2 files changed

+12
-43
lines changed

jdbc/src/test/java/tech/ydb/jdbc/impl/YdbPreparedStatementImplTest.java

Lines changed: 6 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -63,16 +63,16 @@ public class YdbPreparedStatementImplTest {
6363

6464
@BeforeAll
6565
public static void initTable() throws SQLException {
66-
try (Statement statement = jdbc.connection().createStatement();) {
66+
try (PreparedStatement ps = jdbc.connection().prepareStatement(TEST_TABLE.createTableSQL())) {
6767
// create test table
68-
statement.execute(TEST_TABLE.createTableSQL());
68+
ps.execute();
6969
}
7070
}
7171

7272
@AfterAll
7373
public static void dropTable() throws SQLException {
74-
try (Statement statement = jdbc.connection().createStatement();) {
75-
statement.execute(TEST_TABLE.dropTableSQL());
74+
try (PreparedStatement ps = jdbc.connection().prepareStatement(TEST_TABLE.dropTableSQL())) {
75+
ps.execute();
7676
}
7777
}
7878

@@ -82,8 +82,8 @@ public void afterEach() throws SQLException {
8282
return;
8383
}
8484

85-
try (Statement statement = jdbc.connection().createStatement()) {
86-
statement.execute(TEST_TABLE.deleteAllSQL());
85+
try (PreparedStatement ps = jdbc.connection().prepareStatement(TEST_TABLE.deleteAllSQL())) {
86+
ps.execute();
8787
}
8888

8989
jdbc.connection().close();
@@ -429,19 +429,6 @@ public void executeScanQueryAsUpdate() throws SQLException {
429429
}
430430
}
431431

432-
@Test
433-
public void executeUnsupportedModes() throws SQLException {
434-
ExceptionAssert.sqlException("Query type in prepared statement not supported: SCHEME_QUERY", () -> {
435-
String sql = "DROP TABLE test_table;";
436-
jdbc.connection().prepareStatement(sql);
437-
});
438-
439-
ExceptionAssert.sqlException("Query type in prepared statement not supported: EXPLAIN_QUERY", () -> {
440-
String sql = "EXPLAIN " + prepareSelectAll();
441-
jdbc.connection().prepareStatement(sql);
442-
});
443-
}
444-
445432
@ParameterizedTest(name = "with {0}")
446433
@EnumSource(value = SqlQueries.YqlQuery.class)
447434
public void executeExplainQueryExplicitly(SqlQueries.YqlQuery mode) throws SQLException {

jdbc/src/test/java/tech/ydb/jdbc/impl/YdbQueryPreparedStatementImplTest.java

Lines changed: 6 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -61,16 +61,16 @@ public class YdbQueryPreparedStatementImplTest {
6161

6262
@BeforeAll
6363
public static void initTable() throws SQLException {
64-
try (Statement statement = jdbc.connection().createStatement();) {
64+
try (PreparedStatement ps = jdbc.connection().prepareStatement(TEST_TABLE.createTableSQL())) {
6565
// create test table
66-
statement.execute(TEST_TABLE.createTableSQL());
66+
ps.execute();
6767
}
6868
}
6969

7070
@AfterAll
7171
public static void dropTable() throws SQLException {
72-
try (Statement statement = jdbc.connection().createStatement();) {
73-
statement.execute(TEST_TABLE.dropTableSQL());
72+
try (PreparedStatement ps = jdbc.connection().prepareStatement(TEST_TABLE.dropTableSQL())) {
73+
ps.execute();
7474
}
7575
}
7676

@@ -80,8 +80,8 @@ public void afterEach() throws SQLException {
8080
return;
8181
}
8282

83-
try (Statement statement = jdbc.connection().createStatement()) {
84-
statement.execute(TEST_TABLE.deleteAllSQL());
83+
try (PreparedStatement ps = jdbc.connection().prepareStatement(TEST_TABLE.deleteAllSQL())) {
84+
ps.execute();
8585
}
8686

8787
jdbc.connection().close();
@@ -94,11 +94,6 @@ private String upsertSql(String column, String type) {
9494
.replaceAll("#tableName", TEST_TABLE_NAME);
9595
}
9696

97-
private YdbPreparedStatement prepareUpsert(YdbPrepareMode mode,String column, String type)
98-
throws SQLException {
99-
return jdbc.connection().unwrap(YdbConnection.class).prepareStatement(upsertSql(column, type), mode);
100-
}
101-
10297
private PreparedStatement prepareSimpleSelect(String column) throws SQLException {
10398
String sql = SIMPLE_SELECT_SQL
10499
.replaceAll("#column", column)
@@ -375,19 +370,6 @@ public void executeScanQueryAsUpdate() throws SQLException {
375370
}
376371
}
377372

378-
@Test
379-
public void executeUnsupportedModes() throws SQLException {
380-
ExceptionAssert.sqlException("Query type in prepared statement not supported: SCHEME_QUERY", () -> {
381-
String sql = "DROP TABLE test_table;";
382-
jdbc.connection().prepareStatement(sql);
383-
});
384-
385-
ExceptionAssert.sqlException("Query type in prepared statement not supported: EXPLAIN_QUERY", () -> {
386-
String sql = "EXPLAIN " + prepareSelectAll();
387-
jdbc.connection().prepareStatement(sql);
388-
});
389-
}
390-
391373
@ParameterizedTest(name = "with {0}")
392374
@EnumSource(value = SqlQueries.YqlQuery.class)
393375
public void executeExplainQueryExplicitly(SqlQueries.YqlQuery mode) throws SQLException {

0 commit comments

Comments
 (0)