From 670fee7653f607ff0fc9eb100d2f20c88f888b3d Mon Sep 17 00:00:00 2001 From: Yu Shuaipeng Date: Fri, 24 Aug 2018 18:51:10 +0800 Subject: [PATCH 1/2] fix ComStmtSendLongData --- server/conn_stmt.go | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/server/conn_stmt.go b/server/conn_stmt.go index 9ab74ec2cb72e..fc93f8f253938 100644 --- a/server/conn_stmt.go +++ b/server/conn_stmt.go @@ -249,8 +249,9 @@ func parseStmtArgs(args []interface{}, boundParams [][]byte, nullBitmap, paramTy args[i] = nil continue } - if boundParams[i] != nil { - args[i] = boundParams[i] + if boundParamLength := len(boundParams[i]); boundParamLength != 0 { + // Trim out the last ending byte. + args[i] = boundParams[i][:boundParamLength-1] continue } @@ -509,7 +510,8 @@ func (cc *clientConn) handleStmtSendLongData(data []byte) (err error) { } paramID := int(binary.LittleEndian.Uint16(data[4:6])) - return stmt.AppendParam(paramID, data[6:]) + // Append an extra 0 to the end to distinguish no data and no parameter. + return stmt.AppendParam(paramID, append(data[6:], 0)) } func (cc *clientConn) handleStmtReset(data []byte) (err error) { From 10de78ff93e0dc9a0c2da92b4c97c06d0c7cd1c2 Mon Sep 17 00:00:00 2001 From: Yu Shuaipeng Date: Mon, 27 Aug 2018 11:33:37 +0800 Subject: [PATCH 2/2] address comments --- server/conn_stmt.go | 8 +++----- server/driver_tidb.go | 7 ++++++- 2 files changed, 9 insertions(+), 6 deletions(-) diff --git a/server/conn_stmt.go b/server/conn_stmt.go index fc93f8f253938..9ab74ec2cb72e 100644 --- a/server/conn_stmt.go +++ b/server/conn_stmt.go @@ -249,9 +249,8 @@ func parseStmtArgs(args []interface{}, boundParams [][]byte, nullBitmap, paramTy args[i] = nil continue } - if boundParamLength := len(boundParams[i]); boundParamLength != 0 { - // Trim out the last ending byte. - args[i] = boundParams[i][:boundParamLength-1] + if boundParams[i] != nil { + args[i] = boundParams[i] continue } @@ -510,8 +509,7 @@ func (cc *clientConn) handleStmtSendLongData(data []byte) (err error) { } paramID := int(binary.LittleEndian.Uint16(data[4:6])) - // Append an extra 0 to the end to distinguish no data and no parameter. - return stmt.AppendParam(paramID, append(data[6:], 0)) + return stmt.AppendParam(paramID, data[6:]) } func (cc *clientConn) handleStmtReset(data []byte) (err error) { diff --git a/server/driver_tidb.go b/server/driver_tidb.go index 0967ca5eebc04..739e253e7422e 100644 --- a/server/driver_tidb.go +++ b/server/driver_tidb.go @@ -85,7 +85,12 @@ func (ts *TiDBStatement) AppendParam(paramID int, data []byte) error { if paramID >= len(ts.boundParams) { return mysql.NewErr(mysql.ErrWrongArguments, "stmt_send_longdata") } - ts.boundParams[paramID] = append(ts.boundParams[paramID], data...) + // If len(data) is 0, append an empty byte slice to the end to distinguish no data and no parameter. + if len(data) == 0 { + ts.boundParams[paramID] = []byte{} + } else { + ts.boundParams[paramID] = append(ts.boundParams[paramID], data...) + } return nil }