[BUGFIX] fix text type compact mysql-jdbc

This commit is contained in:
skylhd
2023-08-28 14:40:36 +00:00
committed by ob-robot
parent fa01066739
commit 0be43963ed
5 changed files with 25 additions and 9 deletions

View File

@ -357,10 +357,15 @@ int ObField::get_field_mb_length(const ObObjType type,
int64_t mbmaxlen = 1; int64_t mbmaxlen = 1;
if (OB_FAIL(common::ObCharset::get_mbmaxlen_by_coll(charsetnr, mbmaxlen))) { if (OB_FAIL(common::ObCharset::get_mbmaxlen_by_coll(charsetnr, mbmaxlen))) {
LOG_WARN("fail to get mbmaxlen", K(charsetnr), K(ret)); LOG_WARN("fail to get mbmaxlen", K(charsetnr), K(ret));
} else {
if (lib::is_mysql_mode() && tc == ObTextTC) {
// compat mysql-jdbc 8.x for judge text type by length
length = static_cast<uint32_t>(ObAccuracy::MAX_ACCURACY[type].get_length() - 1);
} else { } else {
length = static_cast<uint32_t>(accuracy.get_length() * mbmaxlen); length = static_cast<uint32_t>(accuracy.get_length() * mbmaxlen);
} }
} }
}
break; break;
} }
case ObRawTC: case ObRawTC:

View File

@ -382,6 +382,7 @@ int ObMPStmtExecute::response_result_for_arraybinding(
for (int64_t i = 0; OB_SUCC(ret) && i < arraybinding_columns_->count(); ++i) { for (int64_t i = 0; OB_SUCC(ret) && i < arraybinding_columns_->count(); ++i) {
ObMySQLField field; ObMySQLField field;
OZ (ObMySQLResultSet::to_mysql_field(arraybinding_columns_->at(i), 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); OMPKField fp(field);
OZ (response_packet(fp, &session_info)); OZ (response_packet(fp, &session_info));
} }

View File

@ -1208,8 +1208,8 @@ int ObMPStmtPrexecute::send_param_field_packet(ObSQLSessionInfo &session,
if (OB_FAIL(ObMySQLResultSet::to_mysql_field(ob_field, field))) { if (OB_FAIL(ObMySQLResultSet::to_mysql_field(ob_field, field))) {
LOG_WARN("fail to copy param field", K(ob_field)); LOG_WARN("fail to copy param field", K(ob_field));
} else { } else {
OMPKField fp(field);
ObMySQLResultSet::replace_lob_type(session, ob_field, field); ObMySQLResultSet::replace_lob_type(session, ob_field, field);
OMPKField fp(field);
if (OB_FAIL(response_packet(fp, &session))) { if (OB_FAIL(response_packet(fp, &session))) {
LOG_DEBUG("response packet fail", K(ret)); LOG_DEBUG("response packet fail", K(ret));
} else { } else {
@ -1235,6 +1235,7 @@ int ObMPStmtPrexecute::send_param_packet(ObSQLSessionInfo &session,
param_field.type_.set_type(ObIntType); // @bug param_field.type_.set_type(ObIntType); // @bug
param_field.cname_ = ObString::make_string("?"); param_field.cname_ = ObString::make_string("?");
OZ (ObMySQLResultSet::to_mysql_field(param_field, field)); OZ (ObMySQLResultSet::to_mysql_field(param_field, field));
ObMySQLResultSet::replace_lob_type(session, param_field, field);
OMPKField fp(field); OMPKField fp(field);
OZ (response_packet(fp, &session)); OZ (response_packet(fp, &session));
} }

View File

@ -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_)); 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;
}
} }
} }

View File

@ -265,7 +265,7 @@ def substr(v,1) 253 512 0 Y 0 0 45
##cast test ##cast test
select substr(cast(date_c as char(1024)), 0) from build_in_func_test_table; 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 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) | | 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; 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 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) | | 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; 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 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) | | 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; 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 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))) | | 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; 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 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))) | | 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; 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 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))) | | 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))); 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 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))) | | unhex(cast(repeat('123',5) as char(1024))) |
+--------------------------------------------+ +--------------------------------------------+