Skip to content

Commit 35d6699

Browse files
committed
Merge branch 'main' into issue-2329
# Conflicts: # jdbc-v2/src/test/java/com/clickhouse/jdbc/PreparedStatementTest.java
2 parents a0dd199 + df339eb commit 35d6699

File tree

3 files changed

+27
-9
lines changed

3 files changed

+27
-9
lines changed

jdbc-v2/src/main/java/com/clickhouse/jdbc/PreparedStatementImpl.java

+3-7
Original file line numberDiff line numberDiff line change
@@ -43,13 +43,7 @@
4343
import java.time.format.DateTimeFormatter;
4444
import java.time.format.DateTimeFormatterBuilder;
4545
import java.time.temporal.ChronoField;
46-
import java.util.ArrayList;
47-
import java.util.Arrays;
48-
import java.util.Calendar;
49-
import java.util.Collection;
50-
import java.util.Collections;
51-
import java.util.List;
52-
import java.util.Map;
46+
import java.util.*;
5347

5448
public class PreparedStatementImpl extends StatementImpl implements PreparedStatement, JdbcV2Wrapper {
5549
private static final Logger LOG = LoggerFactory.getLogger(PreparedStatementImpl.class);
@@ -661,6 +655,8 @@ private static String encodeObject(Object x) throws SQLException {
661655
}
662656
tupleString.append(")");
663657
return tupleString.toString();
658+
} else if (x instanceof UUID) {
659+
return "'" + escapeString(((UUID) x).toString()) + "'";
664660
}
665661

666662
return escapeString(x.toString());//Escape single quotes

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

+23-1
Original file line numberDiff line numberDiff line change
@@ -579,6 +579,29 @@ void testClearParameters() throws Exception {
579579
}
580580
}
581581

582+
@Test(groups = {"integration"})
583+
void testWriteUUID() throws Exception {
584+
String sql = "insert into `test_issue_2327` (`id`, `uuid`) values (?, ?)";
585+
try (Connection conn = getJdbcConnection();
586+
PreparedStatementImpl ps = (PreparedStatementImpl) conn.prepareStatement(sql)) {
587+
588+
try (Statement stmt = conn.createStatement()) {
589+
stmt.execute("CREATE TABLE IF NOT EXISTS `test_issue_2327` (`id` Nullable(String), `uuid` UUID) ENGINE Memory;");
590+
}
591+
UUID uuid = UUID.randomUUID();
592+
ps.setString(1, "testId01");
593+
ps.setObject(2, uuid);
594+
ps.execute();
595+
596+
try (Statement stmt = conn.createStatement()) {
597+
ResultSet rs = stmt.executeQuery("SELECT count(*) FROM `test_issue_2327`");
598+
Assert.assertTrue(rs.next());
599+
Assert.assertEquals(rs.getInt(1), 1);
600+
}
601+
}
602+
603+
}
604+
582605
@Test(groups = {"integration"})
583606
void testWriteCollection() throws Exception {
584607
String sql = "insert into `test_issue_2329` (`id`, `name`, `age`, `arr`) values (?, ?, ?, ?)";
@@ -605,5 +628,4 @@ void testWriteCollection() throws Exception {
605628
}
606629

607630
}
608-
609631
}

performance/pom.xml

+1-1
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<properties>
1616
<apache.httpclient.version>5.3.1</apache.httpclient.version>
1717
<slf4j.version>2.0.17</slf4j.version>
18-
<ch.jdbc.revision>0.8.3-SNAPSHOT</ch.jdbc.revision>
18+
<ch.jdbc.revision>0.8.4-SNAPSHOT</ch.jdbc.revision>
1919
<jmh.version>1.37</jmh.version>
2020
<testcontainers.version>1.20.6</testcontainers.version>
2121

0 commit comments

Comments
 (0)