Skip to content
Merged
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
20 changes: 12 additions & 8 deletions jdbc-v2/src/main/java/com/clickhouse/jdbc/ResultSetImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -328,7 +328,7 @@ public String getString(String columnLabel) throws SQLException {
}
}

/**
/**
* Cuts the text of a {@code FixedString} column after its last valid UTF-8 character. The server pads a
* {@code FixedString(N)} value that is shorter than {@code N} bytes with zero bytes, and a value that is cut to
* {@code N} bytes can end in an incomplete multi-byte character. The UTF-8 decoding gives {@code '\0'} for a zero
Expand All @@ -337,16 +337,20 @@ public String getString(String columnLabel) throws SQLException {
* with the last complete character. The same characters inside the value are kept. The text of other column
* types is returned unchanged.
*/
private String trimFixedString(String columnLabel, String value) {
int end = value.length();
while (end > 0 && (value.charAt(end - 1) == '\0' || value.charAt(end - 1) == '\uFFFD')) {
end--;
private String trimFixedString(String columnLabel, String value) {
if (getSchema().getColumnByName(columnLabel).getValueDataType() != ClickHouseDataType.FixedString) {
return value;
}
final int originalLength = value.length();
int lastCharPos = originalLength - 1;
while (lastCharPos >= 0 && (value.charAt(lastCharPos) == '\0' || value.charAt(lastCharPos) == '\uFFFD')) {
lastCharPos--;
}
if (end == value.length()
|| getSchema().getColumnByName(columnLabel).getValueDataType() != ClickHouseDataType.FixedString) {
final int trimmedLength = lastCharPos + 1;
if (trimmedLength == originalLength) {
return value;
}
return value.substring(0, end);
return value.substring(0, trimmedLength);
}

@Override
Expand Down
Loading