From 6aa67d8eb5a99d0f74d66ced82fae71dce04b688 Mon Sep 17 00:00:00 2001 From: fengjiayao Date: Mon, 4 Dec 2023 15:41:04 +0800 Subject: [PATCH 1/2] =?UTF-8?q?=E4=BF=AE=E5=A4=8DCOM=5FSTMT=5FEXECUTE?= =?UTF-8?q?=EF=BC=8Cnew=5Fparams=5Fbind=5Fflag=E4=B8=BA0=E5=88=86=E6=94=AF?= =?UTF-8?q?=E7=9A=84=E5=8D=8F=E8=AE=AE=E5=A4=84=E7=90=86bug=EF=BC=9A?= =?UTF-8?q?=E6=B2=A1=E6=9C=89=E5=A4=8D=E7=94=A8parameter=5Ftypes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- proxy/server/conn_stmt.go | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/proxy/server/conn_stmt.go b/proxy/server/conn_stmt.go index a5d258a8..5a5abb07 100644 --- a/proxy/server/conn_stmt.go +++ b/proxy/server/conn_stmt.go @@ -44,7 +44,8 @@ type Stmt struct { params int columns int - args []interface{} + paramTypes []byte + args []interface{} s sqlparser.Statement @@ -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)) { @@ -227,8 +229,10 @@ func (c *ClientConn) handleStmtExecute(data []byte) error { paramTypes = data[pos : pos+(paramNum<<1)] pos += (paramNum << 1) - paramValues = data[pos:] + //paramValues = data[pos:] } + // new_params_bind_flag 为 false,客户端在发送 COM_STMT_EXECUTE 命令时不需要再次发送 parameter_types + paramValues = data[pos:] if err := c.bindStmtArgs(s, nullBitmaps, paramTypes, paramValues); err != nil { return err @@ -332,6 +336,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 From c23e4747848b2635853d3c1ff8523a0941257f5e Mon Sep 17 00:00:00 2001 From: fengjiayao Date: Mon, 4 Dec 2023 16:41:35 +0800 Subject: [PATCH 2/2] =?UTF-8?q?=E4=BF=AE=E5=A4=8DCOM=5FSTMT=5FEXECUTE?= =?UTF-8?q?=EF=BC=8Cnew=5Fparams=5Fbind=5Fflag=E4=B8=BA0=E5=88=86=E6=94=AF?= =?UTF-8?q?=E7=9A=84=E5=8D=8F=E8=AE=AE=E5=A4=84=E7=90=86bug=EF=BC=9A?= =?UTF-8?q?=E6=B2=A1=E6=9C=89=E5=A4=8D=E7=94=A8parameter=5Ftypes?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- proxy/server/conn_stmt.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/proxy/server/conn_stmt.go b/proxy/server/conn_stmt.go index 5a5abb07..4fc7d63e 100644 --- a/proxy/server/conn_stmt.go +++ b/proxy/server/conn_stmt.go @@ -230,8 +230,10 @@ func (c *ClientConn) handleStmtExecute(data []byte) error { pos += (paramNum << 1) //paramValues = data[pos:] + } else { + // new_params_bind_flag 为 false,客户端在发送 COM_STMT_EXECUTE 命令时不需要再次发送 parameter_types + pos++ } - // new_params_bind_flag 为 false,客户端在发送 COM_STMT_EXECUTE 命令时不需要再次发送 parameter_types paramValues = data[pos:] if err := c.bindStmtArgs(s, nullBitmaps, paramTypes, paramValues); err != nil {