[CP] fix select into outfile with gbk encoding bug

This commit is contained in:
wjhh2008
2023-10-24 03:40:00 +00:00
committed by ob-robot
parent 9924d93c54
commit 61992d25e1
2 changed files with 16 additions and 4 deletions

View File

@ -578,7 +578,8 @@ public:
template<typename foreach_char_func>
static int foreach_char(const common::ObString &str,
common::ObCollationType collation_type,
foreach_char_func &func)
foreach_char_func &func,
bool ignore_invalid_character = false)
{
int ret = common::OB_SUCCESS;
int32_t wchar = 0;
@ -587,8 +588,19 @@ public:
for (common::ObString temp_str = str; OB_SUCC(ret) && !temp_str.empty(); temp_str+=length) {
if (OB_FAIL(ObCharset::mb_wc(collation_type, temp_str.ptr(), temp_str.length(), length, wchar))) {
COMMON_LOG(WARN, "fail to call mb_wc", K(ret), KPHEX(temp_str.ptr(), temp_str.length()));
} else {
COMMON_LOG(WARN, "fail to call mb_wc", K(ret), KPHEX(temp_str.ptr(), temp_str.length()), K(ignore_invalid_character));
if (OB_ERR_INCORRECT_STRING_VALUE == ret && ignore_invalid_character) {
ret = common::OB_SUCCESS;
wchar = INT32_MAX;
length = ObCharset::is_mbchar(collation_type, temp_str.ptr(), temp_str.ptr() + temp_str.length());
if (length <= 0) {
int64_t min_len = 0;
ObCharset::get_mbminlen_by_coll(collation_type, min_len);
length = static_cast<int32_t>(min_len);
}
}
}
if (OB_SUCC(ret)) {
encoding.assign_ptr(temp_str.ptr(), length);
if (OB_FAIL(func(encoding, wchar))) {
COMMON_LOG(WARN, "fail to call func", K(ret), K(encoding),

View File

@ -277,7 +277,7 @@ int ObExprToOutfileRow::print_field(char *buf, const int64_t buf_len, int64_t &p
return ret;
};
ObString tmp_str(out_info.tmp_buf_len_, tmp_pos, out_info.tmp_buf_);
OZ(ObCharsetUtils::foreach_char(tmp_str, out_info.print_params_.cs_type_, escape_func));
OZ(ObCharsetUtils::foreach_char(tmp_str, out_info.print_params_.cs_type_, escape_func, true));
}
if (need_enclose) {
OZ(out_info.enclose_.print_plain_str_literal(buf, buf_len, pos, out_info.print_params_));