From 6447906ef3e72a0ee3d45aa70d7e46fade65534c Mon Sep 17 00:00:00 2001 From: 0xacc Date: Fri, 30 Dec 2022 10:38:14 +0000 Subject: [PATCH] [to #35400270] fix padding of PL CHAR variables in PAD_CHAR_TO_FULL_LENGTH sql_mode --- src/sql/ob_spi.cpp | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/src/sql/ob_spi.cpp b/src/sql/ob_spi.cpp index 9609cbba9e..ef48211ef3 100644 --- a/src/sql/ob_spi.cpp +++ b/src/sql/ob_spi.cpp @@ -769,8 +769,22 @@ int ObSPIService::spi_calc_expr(ObPLExecCtx *ctx, if (OB_SUCC(ret) && result->is_character_type()) { - OZ (spi_pad_char_or_varchar( - ctx->exec_ctx_->get_my_session(), expr, ctx->allocator_, result)); + ObObjType type = result->get_type(); + if (lib::is_mysql_mode() && T_QUESTIONMARK == get_expression_type(*expr) && + (ObCharType == type || ObNCharType == type)) { + if (is_pad_char_to_full_length(ctx->exec_ctx_->get_my_session()->get_sql_mode())) { + OZ (spi_pad_char_or_varchar( + ctx->exec_ctx_->get_my_session(), type, result->get_accuracy(), ctx->allocator_, result)); + } else { + ObString res = result->get_string(); + OZ (ObCharsetUtils::remove_char_endspace( // this function only adjust res.data_length_ + res, ObCharset::charset_type_by_coll(result->get_collation_type()))); + OX (result->val_len_ = res.length()); + } + } else { + OZ (spi_pad_char_or_varchar( + ctx->exec_ctx_->get_my_session(), expr, ctx->allocator_, result)); + } } if (OB_SUCC(ret)) {