Fix test cases

This commit is contained in:
Hongqin-Li
2021-09-27 21:16:00 +08:00
committed by wangzelin.wzl
parent e2f3a0741a
commit febfa4863f
2 changed files with 23 additions and 27 deletions

View File

@ -2235,7 +2235,9 @@ int ObCharset::charset_convert(ObIAllocator& alloc, const ObString& in, const Ob
ret = OB_INVALID_ARGUMENT;
LOG_WARN("invalid collation type", K(ret), K(src_cs_type), K(dst_cs_type));
} else {
if (0 == in.length() || charset_type_by_coll(src_cs_type) == charset_type_by_coll(dst_cs_type)) {
if (0 == in.length()
|| charset_type_by_coll(src_cs_type) == charset_type_by_coll(dst_cs_type)
|| charset_type_by_coll(dst_cs_type) == CHARSET_BINARY) {
if (!(convert_flag & COPY_STRING_ON_SAME_CHARSET)) {
out = in;
} else {
@ -2243,6 +2245,24 @@ int ObCharset::charset_convert(ObIAllocator& alloc, const ObString& in, const Ob
LOG_WARN("fail to write string", K(ret), K(in));
}
}
} else if (charset_type_by_coll(src_cs_type) == CHARSET_BINARY) {
char *buf = nullptr;
int32_t align_offset = 0;
int32_t res_buf_len = 0;
int mbminlen = ObCharset::get_charset(dst_cs_type)->mbminlen;
if (mbminlen > 0 && in.length() % mbminlen != 0) {
align_offset = mbminlen - in.length() % mbminlen;
}
res_buf_len = in.length() + align_offset;
if (OB_ISNULL(buf = static_cast<char*>(alloc.alloc(res_buf_len)))) {
ret = OB_ALLOCATE_MEMORY_FAILED;
out.reset();
LOG_WARN("allocate memory failed", K(ret), K(in), K(align_offset));
} else {
MEMCPY(buf + align_offset, in.ptr(), in.length());
MEMSET(buf, 0, align_offset);
out.assign_ptr(buf, res_buf_len);
}
} else {
const uint32_t res_buf_len = in.length() * 4;
uint32_t res_len = 0;