Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -367,6 +367,13 @@ public boolean execute(String sql, QuerySettings settings) throws SQLException {
}
}
return false;
} else if (type == StatementType.USE) {
executeUpdate(sql, settings);
//USE Database
List<String> tokens = JdbcUtils.tokenizeSQL(sql);
this.schema = tokens.get(1).replace("\"", "");
LOG.info("Changed statement schema " + schema);
return false;
} else {
executeUpdate(sql, settings);
return false;
Expand Down
13 changes: 13 additions & 0 deletions jdbc-v2/src/test/java/com/clickhouse/jdbc/StatementTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -559,4 +559,17 @@ void testWithClause() throws Exception {
}
assertEquals(count, 100);
}

@Test(groups = { "integration" })
public void testSwitchDatabase() throws Exception {
String createSql = "CREATE TABLE switchDatabaseWithUse (id UInt8, words String) ENGINE = MergeTree ORDER BY ()";
try (Connection conn = getJdbcConnection()) {
try (Statement stmt = conn.createStatement()) {
assertEquals(stmt.executeUpdate(createSql), 0);
assertEquals(stmt.executeUpdate("CREATE DATABASE \"newDatabase\" ENGINE=Atomic"), 0);
assertFalse(stmt.execute("USE \"newDatabase\""));
assertEquals(stmt.executeUpdate(createSql), 0);
}
}
}
}
Loading