summaryrefslogtreecommitdiffstats
path: root/vendor/github.com/go-sql-driver/mysql/packets.go
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/github.com/go-sql-driver/mysql/packets.go')
-rw-r--r--vendor/github.com/go-sql-driver/mysql/packets.go60
1 files changed, 25 insertions, 35 deletions
diff --git a/vendor/github.com/go-sql-driver/mysql/packets.go b/vendor/github.com/go-sql-driver/mysql/packets.go
index 5e0853767d..9ed6408509 100644
--- a/vendor/github.com/go-sql-driver/mysql/packets.go
+++ b/vendor/github.com/go-sql-driver/mysql/packets.go
@@ -51,7 +51,7 @@ func (mc *mysqlConn) readPacket() ([]byte, error) {
mc.sequence++
// packets with length 0 terminate a previous packet which is a
- // multiple of (2^24)-1 bytes long
+ // multiple of (2^24)−1 bytes long
if pktLen == 0 {
// there was no previous packet
if prevData == nil {
@@ -194,11 +194,7 @@ func (mc *mysqlConn) readHandshakePacket() (data []byte, plugin string, err erro
return nil, "", ErrOldProtocol
}
if mc.flags&clientSSL == 0 && mc.cfg.tls != nil {
- if mc.cfg.TLSConfig == "preferred" {
- mc.cfg.tls = nil
- } else {
- return nil, "", ErrNoTLS
- }
+ return nil, "", ErrNoTLS
}
pos += 2
@@ -290,10 +286,10 @@ func (mc *mysqlConn) writeHandshakeResponsePacket(authResp []byte, plugin string
}
// Calculate packet length and get buffer with that size
- data, err := mc.buf.takeSmallBuffer(pktLen + 4)
- if err != nil {
+ data := mc.buf.takeSmallBuffer(pktLen + 4)
+ if data == nil {
// cannot take the buffer. Something must be wrong with the connection
- errLog.Print(err)
+ errLog.Print(ErrBusyBuffer)
return errBadConnNoWrite
}
@@ -371,10 +367,10 @@ func (mc *mysqlConn) writeHandshakeResponsePacket(authResp []byte, plugin string
// http://dev.mysql.com/doc/internals/en/connection-phase-packets.html#packet-Protocol::AuthSwitchResponse
func (mc *mysqlConn) writeAuthSwitchPacket(authData []byte) error {
pktLen := 4 + len(authData)
- data, err := mc.buf.takeSmallBuffer(pktLen)
- if err != nil {
+ data := mc.buf.takeSmallBuffer(pktLen)
+ if data == nil {
// cannot take the buffer. Something must be wrong with the connection
- errLog.Print(err)
+ errLog.Print(ErrBusyBuffer)
return errBadConnNoWrite
}
@@ -391,10 +387,10 @@ func (mc *mysqlConn) writeCommandPacket(command byte) error {
// Reset Packet Sequence
mc.sequence = 0
- data, err := mc.buf.takeSmallBuffer(4 + 1)
- if err != nil {
+ data := mc.buf.takeSmallBuffer(4 + 1)
+ if data == nil {
// cannot take the buffer. Something must be wrong with the connection
- errLog.Print(err)
+ errLog.Print(ErrBusyBuffer)
return errBadConnNoWrite
}
@@ -410,10 +406,10 @@ func (mc *mysqlConn) writeCommandPacketStr(command byte, arg string) error {
mc.sequence = 0
pktLen := 1 + len(arg)
- data, err := mc.buf.takeBuffer(pktLen + 4)
- if err != nil {
+ data := mc.buf.takeBuffer(pktLen + 4)
+ if data == nil {
// cannot take the buffer. Something must be wrong with the connection
- errLog.Print(err)
+ errLog.Print(ErrBusyBuffer)
return errBadConnNoWrite
}
@@ -431,10 +427,10 @@ func (mc *mysqlConn) writeCommandPacketUint32(command byte, arg uint32) error {
// Reset Packet Sequence
mc.sequence = 0
- data, err := mc.buf.takeSmallBuffer(4 + 1 + 4)
- if err != nil {
+ data := mc.buf.takeSmallBuffer(4 + 1 + 4)
+ if data == nil {
// cannot take the buffer. Something must be wrong with the connection
- errLog.Print(err)
+ errLog.Print(ErrBusyBuffer)
return errBadConnNoWrite
}
@@ -887,7 +883,7 @@ func (stmt *mysqlStmt) writeExecutePacket(args []driver.Value) error {
const minPktLen = 4 + 1 + 4 + 1 + 4
mc := stmt.mc
- // Determine threshold dynamically to avoid packet size shortage.
+ // Determine threshould dynamically to avoid packet size shortage.
longDataSize := mc.maxAllowedPacket / (stmt.paramCount + 1)
if longDataSize < 64 {
longDataSize = 64
@@ -897,17 +893,15 @@ func (stmt *mysqlStmt) writeExecutePacket(args []driver.Value) error {
mc.sequence = 0
var data []byte
- var err error
if len(args) == 0 {
- data, err = mc.buf.takeBuffer(minPktLen)
+ data = mc.buf.takeBuffer(minPktLen)
} else {
- data, err = mc.buf.takeCompleteBuffer()
- // In this case the len(data) == cap(data) which is used to optimise the flow below.
+ data = mc.buf.takeCompleteBuffer()
}
- if err != nil {
+ if data == nil {
// cannot take the buffer. Something must be wrong with the connection
- errLog.Print(err)
+ errLog.Print(ErrBusyBuffer)
return errBadConnNoWrite
}
@@ -933,7 +927,7 @@ func (stmt *mysqlStmt) writeExecutePacket(args []driver.Value) error {
pos := minPktLen
var nullMask []byte
- if maskLen, typesLen := (len(args)+7)/8, 1+2*len(args); pos+maskLen+typesLen >= cap(data) {
+ if maskLen, typesLen := (len(args)+7)/8, 1+2*len(args); pos+maskLen+typesLen >= len(data) {
// buffer has to be extended but we don't know by how much so
// we depend on append after all data with known sizes fit.
// We stop at that because we deal with a lot of columns here
@@ -942,11 +936,10 @@ func (stmt *mysqlStmt) writeExecutePacket(args []driver.Value) error {
copy(tmp[:pos], data[:pos])
data = tmp
nullMask = data[pos : pos+maskLen]
- // No need to clean nullMask as make ensures that.
pos += maskLen
} else {
nullMask = data[pos : pos+maskLen]
- for i := range nullMask {
+ for i := 0; i < maskLen; i++ {
nullMask[i] = 0
}
pos += maskLen
@@ -1083,10 +1076,7 @@ func (stmt *mysqlStmt) writeExecutePacket(args []driver.Value) error {
// In that case we must build the data packet with the new values buffer
if valuesCap != cap(paramValues) {
data = append(data[:pos], paramValues...)
- if err = mc.buf.store(data); err != nil {
- errLog.Print(err)
- return errBadConnNoWrite
- }
+ mc.buf.buf = data
}
pos += len(paramValues)