Skip to content

Commit afa6cdd

Browse files
authored
Merge pull request #932 from zhicwu/grpc-patch
Add test case for #896 and #931
2 parents 7e4675d + b135b29 commit afa6cdd

File tree

1 file changed

+50
-0
lines changed

1 file changed

+50
-0
lines changed

clickhouse-jdbc/src/test/java/com/clickhouse/jdbc/ClickHousePreparedStatementTest.java

+50
Original file line numberDiff line numberDiff line change
@@ -506,6 +506,56 @@ public void testReadWriteEnums() throws SQLException {
506506
}
507507
}
508508

509+
@Test(groups = "integration")
510+
public void testReadWriteString() throws SQLException {
511+
try (ClickHouseConnection conn = newConnection(new Properties());
512+
Statement s = conn.createStatement()) {
513+
s.execute("drop table if exists test_read_write_strings;"
514+
+ "create table test_read_write_strings(id Int32, s1 String, s2 Nullable(String), s3 Array(String), s4 Array(Nullable(String)))engine=Memory");
515+
try (PreparedStatement stmt = conn
516+
.prepareStatement("insert into test_read_write_strings")) {
517+
stmt.setInt(1, 0);
518+
stmt.setObject(2, null);
519+
stmt.setObject(3, null);
520+
stmt.setObject(4, new String[0]);
521+
stmt.setObject(5, new String[0]);
522+
Assert.assertThrows(RuntimeException.class, () -> stmt.execute());
523+
}
524+
try (PreparedStatement stmt = conn
525+
.prepareStatement("insert into test_read_write_strings")) {
526+
stmt.setInt(1, 1);
527+
stmt.setObject(2, "");
528+
stmt.setString(3, "");
529+
stmt.setArray(4, conn.createArrayOf("String", new String[] { "" }));
530+
stmt.setObject(5, new String[] { "" });
531+
stmt.addBatch();
532+
stmt.setInt(1, 2);
533+
stmt.setString(2, "");
534+
stmt.setString(3, null);
535+
stmt.setObject(4, new String[0]);
536+
stmt.setArray(5, conn.createArrayOf("String", new String[] { null }));
537+
stmt.addBatch();
538+
int[] results = stmt.executeBatch();
539+
Assert.assertEquals(results, new int[] { 1, 1 });
540+
}
541+
542+
ResultSet rs = s.executeQuery("select * from test_read_write_strings order by id");
543+
Assert.assertTrue(rs.next());
544+
Assert.assertEquals(rs.getInt(1), 1);
545+
Assert.assertEquals(rs.getString(2), "");
546+
Assert.assertEquals(rs.getObject(3), "");
547+
Assert.assertEquals(rs.getObject(4), new String[] { "" });
548+
Assert.assertEquals(rs.getArray(5).getArray(), new String[] { "" });
549+
Assert.assertTrue(rs.next());
550+
Assert.assertEquals(rs.getInt(1), 2);
551+
Assert.assertEquals(rs.getObject(2), "");
552+
Assert.assertEquals(rs.getString(3), null);
553+
Assert.assertEquals(rs.getArray(4).getArray(), new String[0]);
554+
Assert.assertEquals(rs.getObject(5), new String[] { null });
555+
Assert.assertFalse(rs.next());
556+
}
557+
}
558+
509559
@Test(groups = "integration")
510560
public void testInsertQueryDateTime64() throws SQLException {
511561
try (ClickHouseConnection conn = newConnection(new Properties());

0 commit comments

Comments
 (0)