Skip to content

Commit 5bb09a4

Browse files
authored
Merge pull request #2508 from ClickHouse/fix_prepared_statement_impl
[jdbc] Fix prepared statement impl
2 parents b0851f8 + fbac81e commit 5bb09a4

File tree

12 files changed

+546
-105
lines changed

12 files changed

+546
-105
lines changed

clickhouse-data/src/main/java/com/clickhouse/data/ClickHouseDataType.java

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import java.math.BigInteger;
55
import java.net.Inet4Address;
66
import java.net.Inet6Address;
7+
import java.sql.SQLType;
78
import java.time.Duration;
89
import java.time.Instant;
910
import java.time.LocalDate;
@@ -50,7 +51,7 @@
5051
* modifiers for the underlying base data types.
5152
*/
5253
@SuppressWarnings("squid:S115")
53-
public enum ClickHouseDataType {
54+
public enum ClickHouseDataType implements SQLType {
5455
Bool(Boolean.class, false, false, true, 1, 1, 0, 0, 0, false,0x2D, "BOOLEAN"),
5556
Date(LocalDate.class, false, false, false, 2, 10, 0, 0, 0, false, 0x0F),
5657
Date32(LocalDate.class, false, false, false, 4, 10, 0, 0, 0, false, 0x10),
@@ -264,6 +265,21 @@ private static Set<Class<?>> setOf(Class<?>... args) {
264265

265266
public static final byte TUPLE_WITH_NAMES_BIN_TAG = 0x20;
266267

268+
@Override
269+
public String getName() {
270+
return name();
271+
}
272+
273+
@Override
274+
public String getVendor() {
275+
return "com.clickhouse";
276+
}
277+
278+
@Override
279+
public Integer getVendorTypeNumber() {
280+
return (int) binTag;
281+
}
282+
267283
public enum IntervalKind {
268284
Nanosecond(IntervalNanosecond, ChronoUnit.NANOS, 0x00),
269285
Microsecond(IntervalMicrosecond, ChronoUnit.MICROS, 0x01),

client-v2/src/main/java/com/clickhouse/client/api/DataTypeUtils.java

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,19 @@ public class DataTypeUtils {
2020
/**
2121
* Formatter for the DateTime type.
2222
*/
23-
public static DateTimeFormatter DATETIME_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
23+
public static DateTimeFormatter DATETIME_FORMATTER = DateTimeFormatter.ofPattern("uuuu-MM-dd HH:mm:ss");
2424

2525
/**
2626
* Formatter for the Date type.
2727
*/
28-
public static DateTimeFormatter DATE_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd");
28+
public static DateTimeFormatter DATE_FORMATTER = DateTimeFormatter.ofPattern("uuuu-MM-dd");
2929

3030
/**
3131
* Formatter for the DateTime type with nanoseconds.
3232
*/
33-
public static DateTimeFormatter DATETIME_WITH_NANOS_FORMATTER = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss.nnnnnnnnn");
33+
public static DateTimeFormatter DATETIME_WITH_NANOS_FORMATTER = new DateTimeFormatterBuilder().appendPattern("uuuu-MM-dd HH:mm:ss")
34+
.appendFraction(ChronoField.NANO_OF_SECOND, 0, 9, true)
35+
.toFormatter();
3436

3537
private static final DateTimeFormatter INSTANT_FORMATTER = new DateTimeFormatterBuilder()
3638
.appendValue(ChronoField.INSTANT_SECONDS)

client-v2/src/main/java/com/clickhouse/client/api/data_formats/internal/AbstractBinaryFormatReader.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,8 @@ public static String readAsString(Object value, ClickHouseColumn column) {
348348
case DateTime:
349349
case DateTime32:
350350
return zdt.format(DataTypeUtils.DATETIME_FORMATTER);
351+
case DateTime64:
352+
return zdt.format(DataTypeUtils.DATETIME_WITH_NANOS_FORMATTER);
351353
default:
352354
return value.toString();
353355
}

client-v2/src/main/java/com/clickhouse/client/api/sql/SQLUtils.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,4 +132,8 @@ public static String unquoteIdentifier(String str) {
132132
return str;
133133
}
134134
}
135+
136+
public static String escapeSingleQuotes(String x) {
137+
return x.replace("\\", "\\\\").replace("'", "\\'");//Escape single quotes
138+
}
135139
}

jdbc-v2/src/main/java/com/clickhouse/data/Tuple.java

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
package com.clickhouse.data;
22

3+
import java.util.Arrays;
4+
35
public class Tuple {
46
private final Object[] values;
57
private volatile String output;
@@ -37,4 +39,25 @@ public String toString() {
3739
}
3840
return output;
3941
}
42+
43+
44+
@Override
45+
public boolean equals(Object obj) {
46+
if (this == obj) {
47+
return true;
48+
}
49+
if (obj == null) {
50+
return false;
51+
}
52+
if (obj instanceof Tuple) {
53+
Tuple other = (Tuple) obj;
54+
return Arrays.equals(values, other.values);
55+
}
56+
return false;
57+
}
58+
59+
@Override
60+
public int hashCode() {
61+
return Arrays.hashCode(values);
62+
}
4063
}

0 commit comments

Comments
 (0)