Skip to content

Commit 4ccc7ab

Browse files
committed
added test for db identifier in table
1 parent 204a775 commit 4ccc7ab

File tree

1 file changed

+31
-0
lines changed

1 file changed

+31
-0
lines changed

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

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -873,4 +873,35 @@ public void testJdbcEscapeSyntax() throws Exception {
873873
}
874874
}
875875
}
876+
877+
@Test(groups = {"integration "})
878+
public void testStatementsWithDatabaseInTableIdentifier() throws Exception {
879+
try (Connection conn = getJdbcConnection()) {
880+
final String db1Name = conn.getSchema() + "_db1";
881+
final String table1Name = "table1";
882+
try (Statement stmt = conn.createStatement()) {
883+
stmt.execute("CREATE DATABASE IF NOT EXISTS " + db1Name);
884+
stmt.execute("DROP TABLE IF EXISTS " + db1Name + "." + table1Name);
885+
stmt.execute("CREATE TABLE " + db1Name + "." + table1Name +
886+
"(v1 Int32, v2 Int32) Engine MergeTree ORDER BY ()");
887+
}
888+
889+
String[] tableIdentifier = new String[]{
890+
db1Name + "." + table1Name,
891+
"`" + db1Name + "`.`" + table1Name + "`",
892+
"\"" + db1Name + "\".\"" + table1Name + "\""
893+
};
894+
895+
for (int i = 0; i < tableIdentifier.length; i++) {
896+
String tableId = tableIdentifier[i];
897+
System.out.println(">> " + tableId);
898+
final String insertStmt = "INSERT INTO " + tableId + " VALUES (?, ?)";
899+
try (PreparedStatement stmt = conn.prepareStatement(insertStmt)) {
900+
stmt.setInt(1, i + 10);
901+
stmt.setInt(2, i + 20);
902+
assertEquals(stmt.executeUpdate(), 1);
903+
}
904+
}
905+
}
906+
}
876907
}

0 commit comments

Comments
 (0)