Skip to content

Commit 9786892

Browse files
committed
Merge pull request #114 from s7v7nislands/master
Fix connect to MySQL 4.1
2 parents d40f2bc + 916d7c9 commit 9786892

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

packets.go

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -498,7 +498,7 @@ func (mc *mysqlConn) readColumns(count int) (columns []mysqlField, err error) {
498498
}
499499

500500
// EOF Packet
501-
if data[0] == iEOF && len(data) == 5 {
501+
if data[0] == iEOF && (len(data) == 5 || len(data) == 1) {
502502
if i != count {
503503
err = fmt.Errorf("ColumnsCount mismatch n:%d len:%d", count, len(columns))
504504
}
@@ -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,11 +667,15 @@ func (stmt *mysqlStmt) readPrepareResultPacket() (columnCount uint16, err error)
667667
stmt.paramCount = int(binary.LittleEndian.Uint16(data[pos : pos+2]))
668668
pos += 2
669669

670+
// Reserved [8 bit]
671+
pos++
672+
670673
// Warning count [16 bit uint]
671674
if !stmt.mc.strict {
672675
return
673676
} else {
674-
if binary.LittleEndian.Uint16(data[pos:pos+2]) > 0 {
677+
// Check for warnings count > 0, only available in MySQL > 4.1
678+
if len(data) >= 12 && binary.LittleEndian.Uint16(data[pos:pos+2]) > 0 {
675679
err = stmt.mc.getWarnings()
676680
}
677681
}

0 commit comments

Comments
 (0)