compat convert mistaken code with oracle

This commit is contained in:
SevenJ-swj
2023-08-18 11:44:56 +08:00
committed by ob-robot
parent ee8cd5ee54
commit 902896a63e
6 changed files with 100 additions and 96 deletions

View File

@ -1380,37 +1380,10 @@ static int common_string_string(const ObExpr &expr,
LOG_WARN("alloc memory failed", K(ret));
} else if (OB_FAIL(ObCharset::charset_convert(in_cs_type, in_str.ptr(),
in_str.length(), out_cs_type, buf,
buf_len, result_len))) {
if (CM_IS_IGNORE_CHARSET_CONVERT_ERR(expr.extra_)) {
ObString question_mark = ObCharsetUtils::get_const_str(out_cs_type, '?');
int32_t str_offset = 0;
int64_t buf_offset = 0;
while (str_offset < in_str.length() && buf_offset + question_mark.length() <= buf_len) {
int64_t offset = ObCharset::charpos(in_cs_type,
in_str.ptr() + str_offset, in_str.length() - str_offset, 1);
if (OB_UNLIKELY(0 == offset)) {
break;
}
ret = ObCharset::charset_convert(in_cs_type, in_str.ptr() + str_offset,
offset, out_cs_type, buf + buf_offset, buf_len - buf_offset, result_len);
str_offset += offset;
if (OB_SUCCESS == ret) {
buf_offset += result_len;
} else {
MEMCPY(buf + buf_offset, question_mark.ptr(), question_mark.length());
buf_offset += question_mark.length();
}
}
if (buf_offset > buf_len) {
ret = OB_ERR_UNEXPECTED;
LOG_WARN("buf_offset > buf_len, unexpected", K(ret));
} else {
result_len = buf_offset;
ret = OB_SUCCESS;
LOG_WARN("charset convert failed", K(ret), K(in_cs_type), K(out_cs_type));
res_datum.set_string(buf, result_len);
}
}
buf_len, result_len, lib::is_mysql_mode(),
!CM_IS_IGNORE_CHARSET_CONVERT_ERR(expr.extra_),
ObCharset::is_cs_unicode(out_cs_type) ? 0xFFFD : '?'))) {
LOG_WARN("charset convert failed", K(ret));
} else {
res_datum.set_string(buf, result_len);
}

View File

@ -103,7 +103,24 @@ int ObExprToClob::calc_to_clob_expr(const ObExpr &expr, ObEvalCtx &ctx,
} else {
ObString raw_string = arg->get_string();
ObTextStringDatumResult str_result(expr.datum_meta_.type_, &expr, &ctx, &res);
if (OB_FAIL(str_result.init(raw_string.length()))) {
uint32_t result_len = 0;
ObEvalCtx::TempAllocGuard tmp_alloc_g(ctx);
common::ObArenaAllocator &temp_allocator = tmp_alloc_g.get_allocator();
char *buf = NULL;
int64_t reserve_len = raw_string.length() * 4;
if (OB_ISNULL(buf = (char*)temp_allocator.alloc(reserve_len))) {
ret = OB_ALLOCATE_MEMORY_FAILED;
LOG_WARN("alloc mem failed", K(ret));
} else if (OB_FAIL(ObCharset::charset_convert(cs_type, raw_string.ptr(), raw_string.length(),
cs_type, buf, reserve_len, result_len, false, false,
ObCharset::is_cs_unicode(cs_type) ? 0xFFFD : '?'))) {
LOG_WARN("charset convert failed", K(ret));
} else {
raw_string.assign_ptr(buf, result_len);
}
LOG_DEBUG("try convert param value", K(raw_string), K(ObHexStringWrap(raw_string)), K(cs_type));
if (OB_FAIL(ret)) {
} else if (OB_FAIL(str_result.init(raw_string.length()))) {
LOG_WARN("init lob result failed");
} else if (OB_FAIL(str_result.append(raw_string.ptr(), raw_string.length()))) {
LOG_WARN("append lob result failed");