简体   繁体   中英

MySQL 8.0 concat returns system.byte[] from mediumtext columns

In my company we use a self made ERP system that is working with a MySQL server. The ERP System is coded in C# with Visual Studio 2017, the server version is 5.0.

I try to upgrade MySQL from version 5.0 to the current version 8.0. However, SQL querys with the “concat” command don't seem to work anymore.

For example the query

Concat(Column1, Coalesce(Column2, ''), Column3, Coalesce(Column4, '')) As Result

doesn't return a string, but a system.byte[] object.

I found an article on this topic:

https://bugs.mysql.com/bug.php?id=37485

According to it, I tried to modify the SQL query in the following way:

Concat(cast(Column1 as char), Coalesce(cast(Column2 as char), ''), cast(Column3 as char), Coalesce(cast(Column4 as char), '')) As Result

But it still keeps returning system.byte[].

Then I tried to add

“Respect Binary flags=false” 

to the connection string, but that also didn't work and visual studio throws the following error:

"Keyword not supported. Parametername: respect binary flags"

I discovered that concat works when I only try to concatenate column1 and column2, so I looked for a difference and noticed that column1 and 2 are varchar(50) and column3 and 4 are mediumtext.

I don't understand why the casting of the variables didn't work or whats wrong with the "respect binary flags" parameter. Both seemed to solve the problem in other cases. Does anybody have a hint how I can solve this problem in an easy way? Thanks in advance ..

Try using cast after the concat or coalesce to ensure that the result is of the required type you want. I used 255 chars but you can choose the size you need. Below is the code I used for testing this.

create table testing (
column1 varchar(50),
column2 mediumtext);

insert into testing values ('this','that');

CREATE table temp AS
select CAST(coalesce(column1, column2) AS char(255)) from testing;

DESCRIBE temp;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM