File tree Expand file tree Collapse file tree 1 file changed +11
-2
lines changed Expand file tree Collapse file tree 1 file changed +11
-2
lines changed Original file line number Diff line number Diff line change @@ -91,6 +91,10 @@ func (mc *mysqlConn) readInitPacket() (err error) {
9191 return
9292 }
9393
94+ if data [0 ] == 255 {
95+ return mc .handleErrorPacket (data )
96+ }
97+
9498 // protocol version [1 byte]
9599 if data [0 ] < minProtocolVersion {
96100 err = fmt .Errorf (
@@ -340,11 +344,16 @@ func (mc *mysqlConn) handleErrorPacket(data []byte) error {
340344 // Error Number [16 bit uint]
341345 errno := binary .LittleEndian .Uint16 (data [1 :3 ])
342346
343- // SQL State [# + 5bytes string]
347+ pos := 3
348+
349+ // SQL State [optional: # + 5bytes string]
344350 //sqlstate := string(data[pos : pos+6])
351+ if data [pos ] == 0x23 {
352+ pos = 9
353+ }
345354
346355 // Error Message [string]
347- return fmt .Errorf ("Error %d: %s" , errno , string (data [9 :]))
356+ return fmt .Errorf ("Error %d: %s" , errno , string (data [pos :]))
348357}
349358
350359// Ok Packet
You can’t perform that action at this time.
0 commit comments