Skip to content

Commit 8a7569f

Browse files
committed
Solve 2327 - Does not escape correctly UUID
1 parent a245c1f commit 8a7569f

File tree

2 files changed

+27
-7
lines changed

2 files changed

+27
-7
lines changed

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

Lines changed: 3 additions & 7 deletions
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);
@@ -659,6 +653,8 @@ private static String encodeObject(Object x) throws SQLException {
659653
}
660654
tupleString.append(")");
661655
return tupleString.toString();
656+
} else if (x instanceof UUID) {
657+
return "'" + escapeString(((UUID) x).toString()) + "'";
662658
}
663659

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

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

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
import java.util.Arrays;
1717
import java.util.GregorianCalendar;
1818
import java.util.TimeZone;
19+
import java.util.UUID;
1920

2021
import static org.testng.Assert.assertEquals;
2122
import static org.testng.Assert.assertFalse;
@@ -580,4 +581,27 @@ void testClearParameters() throws Exception {
580581
ps.execute();
581582
}
582583
}
584+
585+
@Test(groups = {"integration"})
586+
void testWriteCollection() throws Exception {
587+
String sql = "insert into `test_issue_2327` (`id`, `uuid`) values (?, ?)";
588+
try (Connection conn = getJdbcConnection();
589+
PreparedStatementImpl ps = (PreparedStatementImpl) conn.prepareStatement(sql)) {
590+
591+
try (Statement stmt = conn.createStatement()) {
592+
stmt.execute("CREATE TABLE IF NOT EXISTS `test_issue_2327` (`id` Nullable(String), `uuid` UUID) ENGINE Memory;");
593+
}
594+
UUID uuid = UUID.randomUUID();
595+
ps.setString(1, "testId01");
596+
ps.setObject(2, uuid);
597+
ps.execute();
598+
599+
try (Statement stmt = conn.createStatement()) {
600+
ResultSet rs = stmt.executeQuery("SELECT count(*) FROM `test_issue_2327`");
601+
Assert.assertTrue(rs.next());
602+
Assert.assertEquals(rs.getInt(1), 1);
603+
}
604+
}
605+
606+
}
583607
}

0 commit comments

Comments
 (0)