Skip to content

Commit 51d2775

Browse files
committed
fix prepared statement error in mysql4.1
1 parent 4a17861 commit 51d2775

File tree

1 file changed

+9
-3
lines changed

1 file changed

+9
-3
lines changed

packets.go

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -629,7 +629,7 @@ func (mc *mysqlConn) readUntilEOF() (err error) {
629629
data, err = mc.readPacket()
630630

631631
// No Err and no EOF Packet
632-
if err == nil && (data[0] != iEOF || len(data) != 5) {
632+
if err == nil && (data[0] != iEOF) {
633633
continue
634634
}
635635
return // Err or EOF
@@ -667,12 +667,18 @@ func (stmt *mysqlStmt) readPrepareResultPacket() (columnCount uint16, err error)
667667
stmt.paramCount = int(binary.LittleEndian.Uint16(data[pos : pos+2]))
668668
pos += 2
669669

670+
// These 24 bits be here when > mysql4.1: see function send_prep_stmt() in sql/sql_prepare.cc
671+
// Guard against a 4.1 client [8 bit uint], always 0
670672
// Warning count [16 bit uint]
671673
if !stmt.mc.strict {
672674
return
673675
} else {
674-
if binary.LittleEndian.Uint16(data[pos:pos+2]) > 0 {
675-
err = stmt.mc.getWarnings()
676+
// See function cli_read_prepare_result() in libmysql/libmysql.c
677+
if len(data) >= 12 {
678+
pos++
679+
if binary.LittleEndian.Uint16(data[pos:pos+2]) > 0 {
680+
err = stmt.mc.getWarnings()
681+
}
676682
}
677683
}
678684
}

0 commit comments

Comments
 (0)