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 numberDiff line numberDiff line change
Expand Up@@ -85,7 +85,7 @@ public byte[] toBytes(Object object) {
}
byte[] b = PVarchar.INSTANCE.toBytes(object);
if (b.length != ((String) object).length()) {
throw newIllegalDataException("CHAR types may only contain single byte characters (" + object + ")");
throw newIllegalDataException("CHAR types may only contain single byte characters.");
}
return b;
}
Expand All@@ -97,7 +97,7 @@ public int toBytes(Object object, byte[] bytes, int offset) {
}
int len = PVarchar.INSTANCE.toBytes(object, bytes, offset);
if (len != ((String) object).length()) {
throw newIllegalDataException("CHAR types may only contain single byte characters (" + object + ")");
throw newIllegalDataException("CHAR types may only contain single byte characters.");
}
return len;
}
Expand All@@ -118,7 +118,7 @@ public Object toObject(byte[] bytes, int offset, int length, PDataType actualTyp
// TODO: UTF-8 decoder that will invert as it decodes
String s = Bytes.toString(bytes, offset, length);
if (length != s.length()) {
throw newIllegalDataException("CHAR types may only contain single byte characters (" + s + ")");
throw newIllegalDataException("CHAR types may only contain single byte characters.");
}
return s;
}
Expand All@@ -142,7 +142,7 @@ public void coerceBytes(ImmutableBytesWritable ptr, Object o, PDataType actualTy
Integer actualMaxLength, Integer actualScale, SortOrder actualModifier,
Integer desiredMaxLength, Integer desiredScale, SortOrder expectedModifier) {
if (o != null && actualType.equals(PVarchar.INSTANCE) && ((String)o).length() != ptr.getLength()) {
throw newIllegalDataException("CHAR types may only contain single byte characters (" + o + ")");
throw newIllegalDataException("CHAR types may only contain single byte characters.");
}
super.coerceBytes(ptr, o, actualType, actualMaxLength, actualScale, actualModifier, desiredMaxLength, desiredScale, expectedModifier);
if (ptr.getLength() > 0 && desiredMaxLength != null &&
Expand DownExpand Up@@ -201,7 +201,7 @@ public int compareTo(Object lhs, Object rhs, PDataType rhsType) {
@Override
public Object toObject(String value) {
if (StringUtil.hasMultiByteChars(value)) {
throw newIllegalDataException("CHAR types may only contain single byte characters (" + value + ")");
throw newIllegalDataException("CHAR types may only contain single byte characters.");
}
return value;
}
Expand Down
Original file line numberDiff line numberDiff line change
Expand Up@@ -631,6 +631,7 @@ public void testUpsertTypeMismatch() throws Exception {

@Test
public void testUpsertMultiByteIntoChar() throws Exception {
String value = "繰り返し曜日マスク";
try {
// Select non agg column in aggregate query
String query = "upsert into ATABLE VALUES (?, ?, ?)";
Expand All@@ -639,7 +640,7 @@ public void testUpsertMultiByteIntoChar() throws Exception {
try {
PreparedStatement statement = conn.prepareStatement(query);
statement.setString(1, "00D300000000XHP");
statement.setString(2, "繰り返し曜日マスク");
statement.setString(2, value);
statement.setInt(3, 1);
statement.executeUpdate();
fail();
Expand All@@ -649,6 +650,7 @@ public void testUpsertMultiByteIntoChar() throws Exception {
} catch (SQLException e) {
assertTrue(e.getMessage(), e.getMessage().contains("ERROR 201 (22000): Illegal data."));
assertTrue(e.getMessage().contains("CHAR types may only contain single byte characters"));
assertFalse(e.getMessage().contains(value));
}
}

Expand Down