Fix test cases
This commit is contained in:
parent
e2f3a0741a
commit
febfa4863f
22
deps/oblib/src/lib/charset/ob_charset.cpp
vendored
22
deps/oblib/src/lib/charset/ob_charset.cpp
vendored
@ -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;
|
||||
|
@ -2886,32 +2886,8 @@ int ObSQLUtils::clear_evaluated_flag(const ObExprPtrIArray& calc_exprs, ObEvalCt
|
||||
int ObSQLUtils::copy_and_convert_string_charset(
|
||||
ObIAllocator& allocator, const ObString& src, ObString& dst, ObCollationType src_coll, ObCollationType dst_coll)
|
||||
{
|
||||
int ret = OB_SUCCESS;
|
||||
|
||||
if (OB_UNLIKELY(!ObCharset::is_valid_collation(src_coll) || !ObCharset::is_valid_collation(dst_coll))) {
|
||||
ret = OB_INVALID_ARGUMENT;
|
||||
LOG_WARN("invalid input collation", K(ret), K(src_coll), K(dst_coll));
|
||||
} else if (OB_ISNULL(src.ptr()) || OB_UNLIKELY(0 >= src.length())) {
|
||||
dst.reset();
|
||||
} else if (ObCharset::charset_type_by_coll(src_coll) == ObCharset::charset_type_by_coll(dst_coll)) {
|
||||
OZ(ob_write_string(allocator, src, dst));
|
||||
} else {
|
||||
const int32_t CharConvertFactorNum = 4;
|
||||
char* buf = nullptr;
|
||||
int32_t buf_len = src.length() * CharConvertFactorNum;
|
||||
uint32_t result_len = 0;
|
||||
if (OB_ISNULL(buf = static_cast<char*>(allocator.alloc(buf_len)))) {
|
||||
ret = OB_ALLOCATE_MEMORY_FAILED;
|
||||
LOG_WARN("allocate memory failed", K(ret), "len", buf_len);
|
||||
} else if (OB_FAIL(
|
||||
ObCharset::charset_convert(src_coll, src.ptr(), src.length(), dst_coll, buf, buf_len, result_len))) {
|
||||
LOG_WARN("fail to do charset convert", K(ret));
|
||||
} else {
|
||||
dst.assign_ptr(buf, result_len);
|
||||
}
|
||||
}
|
||||
|
||||
return ret;
|
||||
return ObCharset::charset_convert(allocator, src, src_coll, dst_coll, dst,
|
||||
ObCharset::COPY_STRING_ON_SAME_CHARSET);
|
||||
}
|
||||
|
||||
int ObSQLUtils::update_session_last_schema_version(
|
||||
|
Loading…
x
Reference in New Issue
Block a user