diff --git a/src/main/java/cc/blynk/clickhouse/ClickHousePreparedStatementImpl.java b/src/main/java/cc/blynk/clickhouse/ClickHousePreparedStatementImpl.java index 8431aae..af8691b 100644 --- a/src/main/java/cc/blynk/clickhouse/ClickHousePreparedStatementImpl.java +++ b/src/main/java/cc/blynk/clickhouse/ClickHousePreparedStatementImpl.java @@ -152,7 +152,7 @@ private void setBind(int parameterIndex, ClickHousePreparedStatementParameter pa } private void setNull(int parameterIndex) { - setBind(parameterIndex, ClickHousePreparedStatementParameter.nullParameter()); + setBind(parameterIndex, ClickHousePreparedStatementParameter.NULL_PARAM); } @Override @@ -215,10 +215,8 @@ public void setBytes(int parameterIndex, byte[] x) throws SQLException { @Override public void setDate(int parameterIndex, Date x) throws SQLException { if (x != null) { - setBind( - parameterIndex, - ClickHouseValueFormatter.formatDate(x, dateTimeZone), - true); + String bind = ClickHouseValueFormatter.formatDate(x, dateTimeZone); + setBind(parameterIndex, bind, true); } else { setNull(parameterIndex); } @@ -227,10 +225,8 @@ public void setDate(int parameterIndex, Date x) throws SQLException { @Override public void setTime(int parameterIndex, Time x) throws SQLException { if (x != null) { - setBind( - parameterIndex, - ClickHouseValueFormatter.formatTime(x, dateTimeTimeZone), - true); + String bind = ClickHouseValueFormatter.formatTime(x, dateTimeTimeZone); + setBind(parameterIndex, bind, true); } else { setNull(parameterIndex); } @@ -239,10 +235,8 @@ public void setTime(int parameterIndex, Time x) throws SQLException { @Override public void setTimestamp(int parameterIndex, Timestamp x) throws SQLException { if (x != null) { - setBind( - parameterIndex, - ClickHouseValueFormatter.formatTimestamp(x, dateTimeTimeZone), - true); + String bind = ClickHouseValueFormatter.formatTimestamp(x, dateTimeTimeZone); + setBind(parameterIndex, bind, true); } else { setNull(parameterIndex); } @@ -291,10 +285,10 @@ public void setArray(int parameterIndex, Array x) throws SQLException { @Override public void setObject(int parameterIndex, Object x) throws SQLException { if (x != null) { - setBind( - parameterIndex, - ClickHousePreparedStatementParameter.fromObject( - x, dateTimeZone, dateTimeTimeZone)); + String bind = ClickHouseValueFormatter.formatObject(x, dateTimeZone, dateTimeTimeZone); + boolean needQuoting = ClickHouseValueFormatter.needsQuoting(x); + ClickHousePreparedStatementParameter bindParam = new ClickHousePreparedStatementParameter(bind,needQuoting); + setBind(parameterIndex, bindParam); } else { setNull(parameterIndex); } diff --git a/src/main/java/cc/blynk/clickhouse/ClickHousePreparedStatementParameter.java b/src/main/java/cc/blynk/clickhouse/ClickHousePreparedStatementParameter.java index a73c226..c99091b 100644 --- a/src/main/java/cc/blynk/clickhouse/ClickHousePreparedStatementParameter.java +++ b/src/main/java/cc/blynk/clickhouse/ClickHousePreparedStatementParameter.java @@ -2,11 +2,9 @@ import cc.blynk.clickhouse.util.ClickHouseValueFormatter; -import java.util.TimeZone; - public final class ClickHousePreparedStatementParameter { - private static final ClickHousePreparedStatementParameter NULL_PARAM = + static final ClickHousePreparedStatementParameter NULL_PARAM = new ClickHousePreparedStatementParameter(null, false); static final ClickHousePreparedStatementParameter TRUE_PARAM = @@ -18,20 +16,6 @@ public final class ClickHousePreparedStatementParameter { private final String stringValue; private final boolean quoteNeeded; - static ClickHousePreparedStatementParameter fromObject(Object x, - TimeZone dateTimeZone, TimeZone dateTimeTimeZone) { - if (x == null) { - return NULL_PARAM; - } - return new ClickHousePreparedStatementParameter( - ClickHouseValueFormatter.formatObject(x, dateTimeZone, dateTimeTimeZone), - ClickHouseValueFormatter.needsQuoting(x)); - } - - static ClickHousePreparedStatementParameter nullParameter() { - return NULL_PARAM; - } - ClickHousePreparedStatementParameter(String stringValue, boolean quoteNeeded) { this.stringValue = stringValue == null ? ClickHouseValueFormatter.NULL_MARKER diff --git a/src/test/java/cc/blynk/clickhouse/ClickHousePreparedStatementParameterTest.java b/src/test/java/cc/blynk/clickhouse/ClickHousePreparedStatementParameterTest.java index beefd70..8e40741 100644 --- a/src/test/java/cc/blynk/clickhouse/ClickHousePreparedStatementParameterTest.java +++ b/src/test/java/cc/blynk/clickhouse/ClickHousePreparedStatementParameterTest.java @@ -10,12 +10,12 @@ public class ClickHousePreparedStatementParameterTest { @Test public void testNullParam() { ClickHousePreparedStatementParameter p0 = - ClickHousePreparedStatementParameter.nullParameter(); + ClickHousePreparedStatementParameter.NULL_PARAM; assertEquals(p0.getRegularValue(), "null"); assertEquals(p0.getBatchValue(), "\\N"); ClickHousePreparedStatementParameter p1 = - ClickHousePreparedStatementParameter.nullParameter(); + ClickHousePreparedStatementParameter.NULL_PARAM; assertEquals(p1, p0); assertSame(p1, p0); }