Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

set names do not work #82

Open
joeytang opened this issue May 22, 2024 · 0 comments
Open

set names do not work #82

joeytang opened this issue May 22, 2024 · 0 comments

Comments

@joeytang
Copy link

joeytang commented May 22, 2024

Bug Report

weir在首次建立与底层mysql连接的时候,没有设置字符集,只是把字符集设置成了属性,并没有实际调用set names 指令,可以看代码如下

c.charset = constant.DefaultCharset

应该改为
c.charset = constant.DefaultCharset
这段删掉
在 handshake之后调用SetCharset,改完如下:
//c.charset = constant.DefaultCharset

// Apply configuration functions.
for i := range options {
	options[i](c)
}

if err = c.handshake(); err != nil {
	return nil, errors.Trace(err)
}
if err = c.SetCharset(constant.DefaultCharset); err != nil {
	return nil, errors.Trace(err)
}

为什么这么改呢?
SetCharset这个函数中有判断
if c.charset == charset {
return nil
}
所以如果c.charset = constant.DefaultCharset进行了赋值,也就是这个连接没有调用set names utf8mb4指令,当我们主动调用SetCharset(ctx, "utf8mb4")的时候,因为c.charset已经是utf8mb4了,就不会再往下执行,也就是不会发送 set name utf8mb4指令,从而导致字符集一次都没有设置过。

What did you do?

What did you expect to see?

What did you see instead?

What version of Weir are you using (weir-proxy -V)?

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

No branches or pull requests

1 participant