Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

prepare方式执行blob类型的insert,[]byte部分字节被编码成�字符存储了 #3

Open
sunbin728 opened this issue Jan 6, 2017 · 11 comments

Comments

@sunbin728
Copy link

mycat1.6版本。prepare方式执行blob类型的insert,[]byte的部分字节被编码成�字符存储了

@sunbin728
Copy link
Author

存入的[]byte 是97个字节
[132 167 65 99 99 111 117 110 116 164 113 113 105 100 169 67 104 97 110 110 101 108 105 100 162 49 49 170 85 112 100 97 116 101 84 105 109 101 179 50 48 49 55 45 48 49 45 48 54 32 49 53 58 48 48 58 48 51 168 67 111 110 116 97 99 116 115 145 130 166 77 111 98 105 108 101 171 49 53 56 57 54 54 54 53 53 50 49 164 78 97 109 101 163 49 49 49]
真正入库的数据变成了125个字节,非utf8编码的字节被转换成了�符号存储
[239 191 189 239 191 189 65 99 99 111 117 110 116 239 191 189 113 113 105 100 239 191 189 67 104 97 110 110 101 108 105 100 239 191 189 49 49 239 191 189 85 112 100 97 116 101 84 105 109 101 239 191 189 50 48 49 55 45 48 49 45 48 54 32 49 53 58 48 48 58 48 51 239 191 189 67 111 110 116 97 99 116 115 239 191 189 239 191 189 239 191 189 77 111 98 105 108 101 239 191 189 49 53 56 57 54 54 54 53 53 50 49 239 191 189 78 97 109 101 239 191 189 49 49 49]
��Account�qqid�Channelid�11�UpdateTime�2017-01-06 15:00:03�Contacts���Mobile�15896665521�Name�111

@sunbin728
Copy link
Author

我测试过,直接存入mysql是没有问题的 ,存进去的仍然是97字节。 通过mycat方式存储就变成了125字节。

@sunbin728
Copy link
Author

@linzhiqiang0514 麻烦看下我遇到的问题,新版本不是说支持blob类型的吗

@sunbin728
Copy link
Author

@magicdoom @micmiu @stonelion @apachemycat 有人可以帮我看一下这个问题吗?

@stonelion
Copy link

在客户端的 jdbc url 上添加 useServerPrepStmts=true,开启服务端 prepare。

@sunbin728
Copy link
Author

@stonelion 我用的是golang, 我也试着添加了 useServerPrepStmts=true连接参数,还是一样的效果。
tdb, err := sql.Open("mysql", "cat:cat@tcp(10.15.108.223:8066)/das?useServerPrepStmts=true")
defer tdb.Close()

strsql := fmt.Sprintf(`INSERT INTO %s(account, channelid, contactsinfo, updatetime) 
VALUES('%s','%s',?, '%s') ON DUPLICATE KEY UPDATE 
channelid=VALUES(channelid), contactsinfo=VALUES(contactsinfo)`,
	config.T_UserContacts, contactlist.Account, contactlist.Channelid, contactlist.UpdateTime)
stmt, err := tdb.Prepare(strsql)
log.Debug("ToDB: Prepare stmt=%v, err=%v", stmt, err)
ret, err := stmt.Exec(data)
log.Debug("ToDB: stmt.Exec ret=%v, err=%v", ret, err)

@stonelion
Copy link

useServerPrepStmts 这个参数是 mysql connectJ 使用的。 go 下的客户端应该有自己的参数。可以找看看客户端具体的配置在哪里。

@sunbin728
Copy link
Author

@stonelion golang没有发现有这个参数,不填这个参数也是可以使用preparestmt功能的, 直接连接mysql也能正常写入byte数组。 但是连接mycat虽然能写入byte数组,但数据被编码成?号了,不是我存入的数据了。
我今天又用java测试了一下,java不用配置这个参数useServerPrepStmts ,数据写入也都没有问题的。不会出现golang里的问题。
哎,晕掉了。 只能说明mycat只支持java写入blob, 对golang不能完全支持?因为golang 直连mysql没有问题。

@zhangjiha
Copy link

我使用Ruby,开启了客户端的预编译之后,仍然无法绕过这个bug。
预编译的指令是生效了的。
不太明白你所说的 开启服务端prepare是什么意思。 mycat有这个配置么?

@talkw-liu
Copy link

talkw-liu commented Jan 25, 2019

@stonelion 帮我看下这个问题,急!#20 (comment)

@pencilkill
Copy link

Hibernate4,mysql数据库类型 blob,java类型 byte[],单开 useServerPrepStmts=true 无法正确处理数据。
注解方式,类型加 @Type(type = "org.hibernate.type.PrimitiveByteArrayBlobType") 后正常

# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants