Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
public class ClickHousePreparedStatementImpl extends ClickHouseStatementImpl implements ClickHousePreparedStatement {

static final String PARAM_MARKER = "?";
static final String NULL_MARKER = "\\N";

private static final Pattern VALUES = Pattern.compile("(?i)VALUES[\\s]*\\(");

Expand Down Expand Up @@ -82,6 +83,8 @@ private String buildSql() throws SQLException {
String pValue = getParameter(i - 1);
if (PARAM_MARKER.equals(pValue)) {
sb.append(binds[p++].getRegularValue());
} else if (NULL_MARKER.equals(pValue)) {
sb.append("NULL");
} else {
sb.append(pValue);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ private static String typeTransformParameterValue(String paramValue) {
return "0";
}
if ("NULL".equalsIgnoreCase(paramValue)) {
return "\\N";
return ClickHousePreparedStatementImpl.NULL_MARKER;
}
return paramValue;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -640,6 +640,25 @@ public void testArrayDateTime() throws Exception {
Assert.assertEquals(result[1].getTime(), 1560698526598L);
}

@Test
public void testStaticNullValue() throws Exception {
connection.createStatement().execute(
"DROP TABLE IF EXISTS test.static_null_value");
connection.createStatement().execute(
"CREATE TABLE IF NOT EXISTS test.static_null_value"
+ "(foo Nullable(String), bar Nullable(String)) "
+ "ENGINE = TinyLog"
);
PreparedStatement ps0 = connection.prepareStatement(
"INSERT INTO test.static_null_value(foo) VALUES (null)");
ps0.executeUpdate();

ps0 = connection.prepareStatement(
"INSERT INTO test.static_null_value(foo, bar) VALUES (null, ?)");
ps0.setNull(1, Types.VARCHAR);
ps0.executeUpdate();
}

private static byte[] randomEncodedUUID() {
UUID uuid = UUID.randomUUID();
return ByteBuffer.allocate(16)
Expand Down