简体   繁体   English

MySQL 8.0 concat 从 mediumtext 列返回 system.byte[]

[英]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.在我的公司,我们使用自制的 ERP 系统,该系统与 MySQL 服务器配合使用。 The ERP System is coded in C# with Visual Studio 2017, the server version is 5.0. ERP 系统使用 C# 编码和 Visual Studio 2017,服务器版本为 5.0。

I try to upgrade MySQL from version 5.0 to the current version 8.0.我尝试将 MySQL 从 5.0 版升级到当前的 8.0 版。 However, SQL querys with the “concat” command don't seem to work anymore.但是,带有“concat”命令的 SQL 查询似乎不再起作用。

For example the query例如查询

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

doesn't return a string, but a system.byte[] object.不返回字符串,而是返回 system.byte[] 对象。

I found an article on this topic:我找到了一篇关于这个主题的文章:

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

According to it, I tried to modify the SQL query in the following way:根据它,我尝试通过以下方式修改SQL查询:

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[].但它仍然不断返回 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:到连接字符串,但这也不起作用,visual studio 抛出以下错误:

"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.我发现当我只尝试连接 column1 和 column2 时,concat 可以工作,所以我寻找了不同之处,并注意到 column1 和 2 是 varchar(50),而 column3 和 4 是中文本。

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.尝试在 concat 或 coalesce 之后使用 cast 以确保结果是您想要的所需类型。 I used 255 chars but you can choose the size you need.我使用了 255 个字符,但您可以选择所需的大小。 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;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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