Skip to content

Commit 7a1a598

Browse files
committed
defer getWarnings() after fetching resultsets.
1 parent e3f0fdc commit 7a1a598

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.strict && 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.strict && mc.warningCount > 0 {
179+
err = mc.getWarnings()
180+
}
178181
return err
179182
}
180183

Diff for: packets.go

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

607607
// warning count [2 bytes]
608608
if !mc.strict {
609+
mc.warningCount = 0
609610
return nil
610611
}
611612

612613
pos := 1 + n + m + 2
614+
mc.warningCount = binary.LittleEndian.Uint16(data[pos : pos+2])
613615
if binary.LittleEndian.Uint16(data[pos:pos+2]) > 0 {
614616
return mc.getWarnings()
615617
}
@@ -729,7 +731,14 @@ func (rows *textRows) readRow(dest []driver.Value) error {
729731
rows.mc.status = readStatus(data[3:])
730732
rows.rs.done = true
731733
if !rows.HasNextResultSet() {
734+
mc := rows.mc
732735
rows.mc = nil
736+
737+
if mc.strict && mc.warningCount > 0 {
738+
if err := mc.getWarnings(); err != nil {
739+
return err
740+
}
741+
}
733742
}
734743
return io.EOF
735744
}
@@ -1115,6 +1124,9 @@ func (mc *mysqlConn) discardResults() error {
11151124
}
11161125
}
11171126
}
1127+
if mc.strict && mc.warningCount > 0 {
1128+
return mc.getWarnings()
1129+
}
11181130
return nil
11191131
}
11201132

0 commit comments

Comments
 (0)