diff --git a/deps/oblib/src/common/ob_field.cpp b/deps/oblib/src/common/ob_field.cpp index a85fe31067..10ad00c1e8 100644 --- a/deps/oblib/src/common/ob_field.cpp +++ b/deps/oblib/src/common/ob_field.cpp @@ -358,7 +358,12 @@ int ObField::get_field_mb_length(const ObObjType type, if (OB_FAIL(common::ObCharset::get_mbmaxlen_by_coll(charsetnr, mbmaxlen))) { LOG_WARN("fail to get mbmaxlen", K(charsetnr), K(ret)); } else { - length = static_cast(accuracy.get_length() * mbmaxlen); + if (lib::is_mysql_mode() && tc == ObTextTC) { + // compat mysql-jdbc 8.x for judge text type by length + length = static_cast(ObAccuracy::MAX_ACCURACY[type].get_length() - 1); + } else { + length = static_cast(accuracy.get_length() * mbmaxlen); + } } } break; diff --git a/src/observer/mysql/obmp_stmt_execute.cpp b/src/observer/mysql/obmp_stmt_execute.cpp index ff8f2e2253..2b670177b0 100644 --- a/src/observer/mysql/obmp_stmt_execute.cpp +++ b/src/observer/mysql/obmp_stmt_execute.cpp @@ -382,6 +382,7 @@ int ObMPStmtExecute::response_result_for_arraybinding( for (int64_t i = 0; OB_SUCC(ret) && i < arraybinding_columns_->count(); ++i) { ObMySQLField field; OZ (ObMySQLResultSet::to_mysql_field(arraybinding_columns_->at(i), field)); + ObMySQLResultSet::replace_lob_type(session_info, arraybinding_columns_->at(i), field); OMPKField fp(field); OZ (response_packet(fp, &session_info)); } diff --git a/src/observer/mysql/obmp_stmt_prexecute.cpp b/src/observer/mysql/obmp_stmt_prexecute.cpp index 94ca36e20d..689c65b392 100644 --- a/src/observer/mysql/obmp_stmt_prexecute.cpp +++ b/src/observer/mysql/obmp_stmt_prexecute.cpp @@ -1208,8 +1208,8 @@ int ObMPStmtPrexecute::send_param_field_packet(ObSQLSessionInfo &session, if (OB_FAIL(ObMySQLResultSet::to_mysql_field(ob_field, field))) { LOG_WARN("fail to copy param field", K(ob_field)); } else { - OMPKField fp(field); ObMySQLResultSet::replace_lob_type(session, ob_field, field); + OMPKField fp(field); if (OB_FAIL(response_packet(fp, &session))) { LOG_DEBUG("response packet fail", K(ret)); } else { @@ -1235,6 +1235,7 @@ int ObMPStmtPrexecute::send_param_packet(ObSQLSessionInfo &session, param_field.type_.set_type(ObIntType); // @bug param_field.cname_ = ObString::make_string("?"); OZ (ObMySQLResultSet::to_mysql_field(param_field, field)); + ObMySQLResultSet::replace_lob_type(session, param_field, field); OMPKField fp(field); OZ (response_packet(fp, &session)); } diff --git a/src/sql/ob_result_set.cpp b/src/sql/ob_result_set.cpp index d95b57c7cc..8cf6cc878c 100644 --- a/src/sql/ob_result_set.cpp +++ b/src/sql/ob_result_set.cpp @@ -1681,6 +1681,15 @@ void ObResultSet::replace_lob_type(const ObSQLSessionInfo &session, } } LOG_TRACE("init field", K(is_use_lob_locator), K(field), K(mfield.type_)); + } else { + if (mfield.type_ == obmysql::EMySQLFieldType::MYSQL_TYPE_TINY_BLOB || + mfield.type_ == obmysql::EMySQLFieldType::MYSQL_TYPE_MEDIUM_BLOB || + mfield.type_ == obmysql::EMySQLFieldType::MYSQL_TYPE_LONG_BLOB) { + // compat mysql-jdbc + // for 5.x, always return MYSQL_TYPE_BLOB + // for 8.x always return MYSQL_TYPE_BLOB, and do text type judge in mysql-jdbc by length + mfield.type_ = obmysql::EMySQLFieldType::MYSQL_TYPE_BLOB; + } } } diff --git a/tools/deploy/mysql_test/test_suite/meta_info/r/mysql/meta_build_in_func_test.result b/tools/deploy/mysql_test/test_suite/meta_info/r/mysql/meta_build_in_func_test.result index 1729b456d2..e7cafe6507 100644 --- a/tools/deploy/mysql_test/test_suite/meta_info/r/mysql/meta_build_in_func_test.result +++ b/tools/deploy/mysql_test/test_suite/meta_info/r/mysql/meta_build_in_func_test.result @@ -265,7 +265,7 @@ def substr(v,1) 253 512 0 Y 0 0 45 ##cast test select substr(cast(date_c as char(1024)), 0) from build_in_func_test_table; Catalog Database Table Table_alias Column Column_alias Type Length Max length Is_null Flags Decimals Charsetnr -def substr(cast(date_c as char(1024)), 0) 251 536870908 0 Y 16 0 45 +def substr(cast(date_c as char(1024)), 0) 252 536870910 0 Y 16 0 45 +---------------------------------------+ | substr(cast(date_c as char(1024)), 0) | +---------------------------------------+ @@ -273,7 +273,7 @@ def substr(cast(date_c as char(1024)), 0) 251 536870908 0 Y 16 0 45 +---------------------------------------+ select substr(cast(date_c as char(1024)), 10) from build_in_func_test_table; Catalog Database Table Table_alias Column Column_alias Type Length Max length Is_null Flags Decimals Charsetnr -def substr(cast(date_c as char(1024)), 10) 251 536870908 17 Y 16 0 45 +def substr(cast(date_c as char(1024)), 10) 252 536870910 17 Y 16 0 45 +----------------------------------------+ | substr(cast(date_c as char(1024)), 10) | +----------------------------------------+ @@ -289,7 +289,7 @@ def substr(cast(1024 as char(1024)), 1, 2) 253 8 2 Y 0 0 45 +----------------------------------------+ select substr(cast(date_c as char(1024)) from 10) from build_in_func_test_table; Catalog Database Table Table_alias Column Column_alias Type Length Max length Is_null Flags Decimals Charsetnr -def substr(cast(date_c as char(1024)) from 10) 251 536870908 17 Y 16 0 45 +def substr(cast(date_c as char(1024)) from 10) 252 536870910 17 Y 16 0 45 +--------------------------------------------+ | substr(cast(date_c as char(1024)) from 10) | +--------------------------------------------+ @@ -573,7 +573,7 @@ def trim(1) 253 4 1 Y 0 0 45 +---------+ select trim(cast(111 as char(1024))) from build_in_func_test_table; Catalog Database Table Table_alias Column Column_alias Type Length Max length Is_null Flags Decimals Charsetnr -def trim(cast(111 as char(1024))) 252 65532 3 Y 16 0 45 +def trim(cast(111 as char(1024))) 252 65535 3 Y 16 0 45 +-------------------------------+ | trim(cast(111 as char(1024))) | +-------------------------------+ @@ -581,7 +581,7 @@ def trim(cast(111 as char(1024))) 252 65532 3 Y 16 0 45 +-------------------------------+ select trim(LEADING '1' from cast(111 as char(1024))) from build_in_func_test_table; Catalog Database Table Table_alias Column Column_alias Type Length Max length Is_null Flags Decimals Charsetnr -def trim(LEADING '1' from cast(111 as char(1024))) 252 65532 0 Y 16 0 45 +def trim(LEADING '1' from cast(111 as char(1024))) 252 65535 0 Y 16 0 45 +------------------------------------------------+ | trim(LEADING '1' from cast(111 as char(1024))) | +------------------------------------------------+ @@ -589,7 +589,7 @@ def trim(LEADING '1' from cast(111 as char(1024))) 252 65532 0 Y 16 0 45 +------------------------------------------------+ select trim(TRAILING '1' from cast(111 as char(1024))) from build_in_func_test_table; Catalog Database Table Table_alias Column Column_alias Type Length Max length Is_null Flags Decimals Charsetnr -def trim(TRAILING '1' from cast(111 as char(1024))) 252 65532 0 Y 16 0 45 +def trim(TRAILING '1' from cast(111 as char(1024))) 252 65535 0 Y 16 0 45 +-------------------------------------------------+ | trim(TRAILING '1' from cast(111 as char(1024))) | +-------------------------------------------------+ @@ -2771,7 +2771,7 @@ def unhex('123') 253 2 2 Y 128 0 63 +--------------+ select unhex(cast(repeat('123',5) as char(1024))); Catalog Database Table Table_alias Column Column_alias Type Length Max length Is_null Flags Decimals Charsetnr -def unhex(cast(repeat('123',5) as char(1024))) 251 536870911 8 Y 144 0 63 +def unhex(cast(repeat('123',5) as char(1024))) 252 536870910 8 Y 144 0 63 +--------------------------------------------+ | unhex(cast(repeat('123',5) as char(1024))) | +--------------------------------------------+