From c1e01ea7de43310114e0401647340e92cbe6cd57 Mon Sep 17 00:00:00 2001 From: obdev Date: Fri, 22 Apr 2022 16:51:14 +0800 Subject: [PATCH] [CP] Remove extra space in sql_mode --- deps/oblib/src/lib/string/ob_string.h | 17 +++++++++++++++++ .../system_variable/ob_system_variable.cpp | 9 +++++---- 2 files changed, 22 insertions(+), 4 deletions(-) diff --git a/deps/oblib/src/lib/string/ob_string.h b/deps/oblib/src/lib/string/ob_string.h index 7121543135..2a54c4e7cd 100644 --- a/deps/oblib/src/lib/string/ob_string.h +++ b/deps/oblib/src/lib/string/ob_string.h @@ -425,6 +425,23 @@ public: return ret; } + const ObString trim_space_only() + { + ObString ret; + if (NULL != ptr_) { + char *start = ptr_; + char *end = ptr_ + data_length_; + while (start < end && ' ' == *start) { + start++; + } + while (start < end && ' ' == *(end - 1)) { + end--; + } + ret.assign_ptr(start, static_cast(end - start)); + } + return ret; + } + static ObString make_string(const char* cstr) { return NULL == cstr ? ObString() : ObString(0, static_cast(strlen(cstr)), const_cast(cstr)); diff --git a/src/share/system_variable/ob_system_variable.cpp b/src/share/system_variable/ob_system_variable.cpp index 02c9c5cabd..f88b580dca 100644 --- a/src/share/system_variable/ob_system_variable.cpp +++ b/src/share/system_variable/ob_system_variable.cpp @@ -1457,11 +1457,12 @@ int ObSqlModeVar::do_check_and_convert(ObExecContext& ctx, const ObSetVar& set_v ret = OB_ERR_UNEXPECTED; LOG_ERROR("unexpected type", K(ret), K(in_val)); } + ObString val_without_space = str_val.trim_space_only(); if (OB_FAIL(ret)) { - } else if (OB_FAIL(find_set(str_val))) { - LOG_WARN("fail to find type", K(ret), K(str_val), K(in_val)); - } else if (OB_FAIL(ob_str_to_sql_mode(str_val, sql_mode))) { - LOG_WARN("fail to convert str to sql mode", K(ret), K(str_val), K(in_val)); + } else if (OB_FAIL(find_set(val_without_space))) { + LOG_WARN("fail to find type", K(ret), K(val_without_space), K(in_val)); + } else if (OB_FAIL(ob_str_to_sql_mode(val_without_space, sql_mode))) { + LOG_WARN("fail to convert str to sql mode", K(ret), K(val_without_space), K(in_val)); } } else if (ob_is_int_tc(in_val.get_type())) { int64_t int64_val = 0; -- GitLab