Skip to content

Commit

Permalink
Updated tests for PreparedStatement
Browse files Browse the repository at this point in the history
  • Loading branch information
alex268 committed Sep 5, 2024
1 parent 6cd1bf6 commit a113328
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 43 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -63,16 +63,16 @@ public class YdbPreparedStatementImplTest {

@BeforeAll
public static void initTable() throws SQLException {
try (Statement statement = jdbc.connection().createStatement();) {
try (PreparedStatement ps = jdbc.connection().prepareStatement(TEST_TABLE.createTableSQL())) {
// create test table
statement.execute(TEST_TABLE.createTableSQL());
ps.execute();
}
}

@AfterAll
public static void dropTable() throws SQLException {
try (Statement statement = jdbc.connection().createStatement();) {
statement.execute(TEST_TABLE.dropTableSQL());
try (PreparedStatement ps = jdbc.connection().prepareStatement(TEST_TABLE.dropTableSQL())) {
ps.execute();
}
}

Expand All @@ -82,8 +82,8 @@ public void afterEach() throws SQLException {
return;
}

try (Statement statement = jdbc.connection().createStatement()) {
statement.execute(TEST_TABLE.deleteAllSQL());
try (PreparedStatement ps = jdbc.connection().prepareStatement(TEST_TABLE.deleteAllSQL())) {
ps.execute();
}

jdbc.connection().close();
Expand Down Expand Up @@ -429,19 +429,6 @@ public void executeScanQueryAsUpdate() throws SQLException {
}
}

@Test
public void executeUnsupportedModes() throws SQLException {
ExceptionAssert.sqlException("Query type in prepared statement not supported: SCHEME_QUERY", () -> {
String sql = "DROP TABLE test_table;";
jdbc.connection().prepareStatement(sql);
});

ExceptionAssert.sqlException("Query type in prepared statement not supported: EXPLAIN_QUERY", () -> {
String sql = "EXPLAIN " + prepareSelectAll();
jdbc.connection().prepareStatement(sql);
});
}

@ParameterizedTest(name = "with {0}")
@EnumSource(value = SqlQueries.YqlQuery.class)
public void executeExplainQueryExplicitly(SqlQueries.YqlQuery mode) throws SQLException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,16 +61,16 @@ public class YdbQueryPreparedStatementImplTest {

@BeforeAll
public static void initTable() throws SQLException {
try (Statement statement = jdbc.connection().createStatement();) {
try (PreparedStatement ps = jdbc.connection().prepareStatement(TEST_TABLE.createTableSQL())) {
// create test table
statement.execute(TEST_TABLE.createTableSQL());
ps.execute();
}
}

@AfterAll
public static void dropTable() throws SQLException {
try (Statement statement = jdbc.connection().createStatement();) {
statement.execute(TEST_TABLE.dropTableSQL());
try (PreparedStatement ps = jdbc.connection().prepareStatement(TEST_TABLE.dropTableSQL())) {
ps.execute();
}
}

Expand All @@ -80,8 +80,8 @@ public void afterEach() throws SQLException {
return;
}

try (Statement statement = jdbc.connection().createStatement()) {
statement.execute(TEST_TABLE.deleteAllSQL());
try (PreparedStatement ps = jdbc.connection().prepareStatement(TEST_TABLE.deleteAllSQL())) {
ps.execute();
}

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

private YdbPreparedStatement prepareUpsert(YdbPrepareMode mode,String column, String type)
throws SQLException {
return jdbc.connection().unwrap(YdbConnection.class).prepareStatement(upsertSql(column, type), mode);
}

private PreparedStatement prepareSimpleSelect(String column) throws SQLException {
String sql = SIMPLE_SELECT_SQL
.replaceAll("#column", column)
Expand Down Expand Up @@ -375,19 +370,6 @@ public void executeScanQueryAsUpdate() throws SQLException {
}
}

@Test
public void executeUnsupportedModes() throws SQLException {
ExceptionAssert.sqlException("Query type in prepared statement not supported: SCHEME_QUERY", () -> {
String sql = "DROP TABLE test_table;";
jdbc.connection().prepareStatement(sql);
});

ExceptionAssert.sqlException("Query type in prepared statement not supported: EXPLAIN_QUERY", () -> {
String sql = "EXPLAIN " + prepareSelectAll();
jdbc.connection().prepareStatement(sql);
});
}

@ParameterizedTest(name = "with {0}")
@EnumSource(value = SqlQueries.YqlQuery.class)
public void executeExplainQueryExplicitly(SqlQueries.YqlQuery mode) throws SQLException {
Expand Down

0 comments on commit a113328

Please sign in to comment.