Skip to content

defer getWarnings() after fetching resultsets. #609

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions connection.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ type mysqlConn struct {
writeTimeout time.Duration
flags clientFlag
status statusFlag
warningCount uint16
sequence uint8
parseTime bool
strict bool
Expand Down
4 changes: 4 additions & 0 deletions driver.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,10 @@ func handleAuthResult(mc *mysqlConn, oldCipher []byte) error {
}
_, err = mc.readResultOK()
}

if err == nil && mc.strict && mc.warningCount > 0 {
return mc.getWarnings()
}
return err
}

Expand Down
1 change: 1 addition & 0 deletions errors.go
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,7 @@ type MySQLWarning struct {
}

func (mc *mysqlConn) getWarnings() (err error) {
mc.warningCount = 0
rows, err := mc.Query("SHOW WARNINGS", nil)
if err != nil {
return
Expand Down
3 changes: 3 additions & 0 deletions infile.go
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,9 @@ func (mc *mysqlConn) handleInFileRequest(name string) (err error) {
// read OK packet
if err == nil {
_, err = mc.readResultOK()
if err == nil && mc.strict && mc.warningCount > 0 {
err = mc.getWarnings()
}
return err
}

Expand Down
12 changes: 12 additions & 0 deletions packets.go
Original file line number Diff line number Diff line change
Expand Up @@ -606,10 +606,12 @@ func (mc *mysqlConn) handleOkPacket(data []byte) error {

// warning count [2 bytes]
if !mc.strict {
mc.warningCount = 0
return nil
}

pos := 1 + n + m + 2
mc.warningCount = binary.LittleEndian.Uint16(data[pos : pos+2])
if binary.LittleEndian.Uint16(data[pos:pos+2]) > 0 {
return mc.getWarnings()
}
Expand Down Expand Up @@ -729,7 +731,14 @@ func (rows *textRows) readRow(dest []driver.Value) error {
rows.mc.status = readStatus(data[3:])
rows.rs.done = true
if !rows.HasNextResultSet() {
mc := rows.mc
rows.mc = nil

if mc.strict && mc.warningCount > 0 {
if err := mc.getWarnings(); err != nil {
return err
}
}
}
return io.EOF
}
Expand Down Expand Up @@ -1115,6 +1124,9 @@ func (mc *mysqlConn) discardResults() error {
}
}
}
if mc.strict && mc.warningCount > 0 {
return mc.getWarnings()
}
return nil
}

Expand Down