Skip to content

Commit ca01562

Browse files
committed
defer getWarnings() after fetching resultsets.
1 parent 382e13d commit ca01562

File tree

5 files changed

+21
-0
lines changed

5 files changed

+21
-0
lines changed

Diff for: connection.go

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ type mysqlConn struct {
3131
sequence uint8
3232
parseTime bool
3333
strict bool
34+
warningCount uint16
3435
}
3536

3637
// Handles parameters set in DSN after the connection is established

Diff for: driver.go

+4
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,10 @@ func handleAuthResult(mc *mysqlConn, oldCipher []byte) error {
175175
}
176176
_, err = mc.readResultOK()
177177
}
178+
179+
if err == nil && mc.warningCount > 0 {
180+
return mc.getWarnings()
181+
}
178182
return err
179183
}
180184

Diff for: errors.go

+1
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ type MySQLWarning struct {
8989
}
9090

9191
func (mc *mysqlConn) getWarnings() (err error) {
92+
mc.warningCount = 0
9293
rows, err := mc.Query("SHOW WARNINGS", nil)
9394
if err != nil {
9495
return

Diff for: infile.go

+3
Original file line numberDiff line numberDiff line change
@@ -175,6 +175,9 @@ func (mc *mysqlConn) handleInFileRequest(name string) (err error) {
175175
// read OK packet
176176
if err == nil {
177177
_, err = mc.readResultOK()
178+
if err == nil && mc.warningCount > 0 {
179+
return mc.getWarnings()
180+
}
178181
return err
179182
}
180183

Diff for: packets.go

+12
Original file line numberDiff line numberDiff line change
@@ -591,10 +591,12 @@ func (mc *mysqlConn) handleOkPacket(data []byte) error {
591591

592592
// warning count [2 bytes]
593593
if !mc.strict {
594+
mc.warningCount = 0
594595
return nil
595596
}
596597

597598
pos := 1 + n + m + 2
599+
mc.warningCount = binary.LittleEndian.Uint16(data[pos : pos+2])
598600
if binary.LittleEndian.Uint16(data[pos:pos+2]) > 0 {
599601
return mc.getWarnings()
600602
}
@@ -714,7 +716,14 @@ func (rows *textRows) readRow(dest []driver.Value) error {
714716
rows.mc.status = readStatus(data[3:])
715717
rows.rs.done = true
716718
if !rows.HasNextResultSet() {
719+
mc := rows.mc
717720
rows.mc = nil
721+
722+
if mc.strict && mc.warningCount > 0 {
723+
if err := mc.getWarnings(); err != nil {
724+
return err
725+
}
726+
}
718727
}
719728
return io.EOF
720729
}
@@ -1100,6 +1109,9 @@ func (mc *mysqlConn) discardResults() error {
11001109
}
11011110
}
11021111
}
1112+
if mc.strict && mc.warningCount > 0 {
1113+
return mc.getWarnings()
1114+
}
11031115
return nil
11041116
}
11051117

0 commit comments

Comments
 (0)