From 92fb30597e811043fe426805923f53c84d8f393c Mon Sep 17 00:00:00 2001 From: GongYusen <986957406@qq.com> Date: Fri, 28 Jun 2024 12:42:23 +0000 Subject: [PATCH] Fix bug: Prepared statement in Oracle mode did not set the length semantics for string variables. --- src/observer/mysql/obmp_stmt_execute.cpp | 26 ++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/src/observer/mysql/obmp_stmt_execute.cpp b/src/observer/mysql/obmp_stmt_execute.cpp index 1f41eac435..4f284bc26e 100644 --- a/src/observer/mysql/obmp_stmt_execute.cpp +++ b/src/observer/mysql/obmp_stmt_execute.cpp @@ -2685,6 +2685,32 @@ int ObMPStmtExecute::parse_param_value(ObIAllocator &allocator, } } } + // set length semantics + if (OB_SUCC(ret) && lib::is_oracle_mode()) { + const ObLengthSemantics default_length_semantics = ctx_.session_info_->get_actual_nls_length_semantics(); + if (MYSQL_TYPE_OB_NVARCHAR2 == type || MYSQL_TYPE_VAR_STRING == type || + MYSQL_TYPE_OB_NCHAR == type || MYSQL_TYPE_VARCHAR == type || + MYSQL_TYPE_STRING == type) { + if (length == 0) { + param.set_length_semantics(default_length_semantics); + } else { + ObLengthSemantics length_semantics = LS_DEFAULT; + if ((MYSQL_TYPE_OB_NVARCHAR2 == type || MYSQL_TYPE_VAR_STRING == type || MYSQL_TYPE_OB_NCHAR == type)) { + length_semantics = LS_CHAR; + } else { + length_semantics = default_length_semantics; + } + if (is_oracle_byte_length(true, length_semantics) + && MYSQL_TYPE_OB_NVARCHAR2 != type + && MYSQL_TYPE_VAR_STRING != type + && MYSQL_TYPE_OB_NCHAR != type) { + param.set_length_semantics(LS_BYTE); + } else { + param.set_length_semantics(LS_CHAR); + } + } + } + } return ret; }