All Downloads are FREE. Search and download functionalities are using the official Maven repository.

cc.blynk.clickhouse.ClickHousePreparedStatementParameter Maven / Gradle / Ivy

There is a newer version: 1.4.4
Show newest version
package cc.blynk.clickhouse;

import cc.blynk.clickhouse.util.ClickHouseValueFormatter;

import java.util.TimeZone;

public final class ClickHousePreparedStatementParameter {

    private static final ClickHousePreparedStatementParameter NULL_PARAM =
        new ClickHousePreparedStatementParameter(null, false);

    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
            : stringValue;
        this.quoteNeeded = quoteNeeded;
    }

    String getRegularValue() {
        if (ClickHouseValueFormatter.NULL_MARKER.equals(stringValue)) {
            return "null";
        }
        if (quoteNeeded) {
            return "'" + stringValue + "'";
        }
        return stringValue;
    }

    String getBatchValue() {
        return stringValue;
    }

    @Override
    public String toString() {
        return stringValue;
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy