This commit is contained in:
hebo
2019-12-26 16:13:36 +08:00
parent 6c2fcd13b2
commit 119d0c9f97
2 changed files with 11 additions and 11 deletions

View File

@@ -55,19 +55,19 @@ func parseResponseHeader(payload []byte) (ok, val int64, err error) {
fmt.Printf("%#v\n", val) fmt.Printf("%#v\n", val)
}() }()
switch { if payload[0] == PACKET_OK && len(payload)>=7 {
case payload[0] == PACKET_OK && len(payload)>=7:
case payload[0] == PACKET_EOF && len(payload)<=9:
// set ok and mysql affected rows number
ok = 1 ok = 1
val = lenencInt(payload) val = lenencInt(payload[1:])
case payload[0] == PACKET_ERR && len(payload)>3: } else if len(payload) > 4 {
payload = payload[4:]
if payload[0] == PACKET_ERR && len(payload)>3 {
// set not ok and mysql execute error-code // set not ok and mysql execute error-code
ok = 0 ok = 0
val = int64(bytesToIntSmallEndian(payload[1:3])) val = int64(bytesToIntSmallEndian(payload[1:3]))
}
default: } else {
err = fmt.Errorf("invalid response packet") err = fmt.Errorf("invalid response packet")
} }
return return

View File

@@ -158,7 +158,7 @@ func (ms *MysqlSession) readFromServer(respSeq int64, bytes []byte) (ok, val int
ms.prepareInfo.prepareStmtID = bytesToInt(contents[1:5]) ms.prepareInfo.prepareStmtID = bytesToInt(contents[1:5])
} }
return parseResponseHeader(contents) return parseResponseHeader(bytes)
} }
err = fmt.Errorf("not need packet") err = fmt.Errorf("not need packet")