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

FIXBUG: 【prepare】修复COM_STMT_EXECUTE,new_params_bind_flag为0分支的协议处理bug:没有复用parameter_types #629

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 12 additions & 2 deletions proxy/server/conn_stmt.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ type Stmt struct {
params int
columns int

args []interface{}
paramTypes []byte
args []interface{}

s sqlparser.Statement

Expand Down Expand Up @@ -218,6 +219,7 @@ func (c *ClientConn) handleStmtExecute(data []byte) error {
pos += nullBitmapLen

//new param bound flag
// https://dev.mysql.com/doc/dev/mysql-server/latest/page_protocol_com_stmt_execute.html
if data[pos] == 1 {
pos++
if len(data) < (pos + (paramNum << 1)) {
Expand All @@ -227,8 +229,12 @@ func (c *ClientConn) handleStmtExecute(data []byte) error {
paramTypes = data[pos : pos+(paramNum<<1)]
pos += (paramNum << 1)

paramValues = data[pos:]
//paramValues = data[pos:]
} else {
// new_params_bind_flag 为 false,客户端在发送 COM_STMT_EXECUTE 命令时不需要再次发送 parameter_types
pos++
}
paramValues = data[pos:]

if err := c.bindStmtArgs(s, nullBitmaps, paramTypes, paramValues); err != nil {
return err
Expand Down Expand Up @@ -332,6 +338,10 @@ func (c *ClientConn) handlePrepareExec(stmt sqlparser.Statement, sql string, arg
}

func (c *ClientConn) bindStmtArgs(s *Stmt, nullBitmap, paramTypes, paramValues []byte) error {
if len(paramTypes) > 0 {
// 缓存paramTypes,供后续使用
s.paramTypes = paramTypes
}
args := s.args

pos := 0
Expand Down