Skip to content

Commit 9e96191

Browse files
committed
proper affectedRows
1 parent 8416bd0 commit 9e96191

File tree

2 files changed

+9
-9
lines changed

2 files changed

+9
-9
lines changed

connection.go

+5-2
Original file line numberDiff line numberDiff line change
@@ -176,10 +176,13 @@ func (mc *mysqlConn) exec(query string) (err error) {
176176
return
177177
}
178178

179-
mc.affectedRows, err = mc.readUntilEOF()
180-
if err != nil {
179+
if mc.affectedRows > 0 {
180+
_, err = mc.readUntilEOF()
181181
return
182182
}
183+
184+
mc.affectedRows, err = mc.readUntilEOF()
185+
return
183186
}
184187

185188
return

packets.go

+4-7
Original file line numberDiff line numberDiff line change
@@ -406,24 +406,23 @@ func (mc *mysqlConn) handleOkPacket(data []byte) (err error) {
406406
// Position
407407
pos := 1
408408

409+
var n int
410+
409411
// Affected rows [Length Coded Binary]
410-
affectedRows, n, err := bytesToLengthCodedBinary(data[pos:])
412+
mc.affectedRows, n, err = bytesToLengthCodedBinary(data[pos:])
411413
if err != nil {
412414
return
413415
}
414416
pos += n
415417

416418
// Insert id [Length Coded Binary]
417-
insertID, n, err := bytesToLengthCodedBinary(data[pos:])
419+
mc.insertId, n, err = bytesToLengthCodedBinary(data[pos:])
418420
if err != nil {
419421
return
420422
}
421423

422424
// Skip remaining data
423425

424-
mc.affectedRows = affectedRows
425-
mc.insertId = insertID
426-
427426
return
428427
}
429428

@@ -602,7 +601,6 @@ func (mc *mysqlConn) readRow(columnsCount int) (*[]*[]byte, error) {
602601
pos += n
603602
}
604603

605-
mc.affectedRows++
606604
return &row, nil
607605
}
608606

@@ -1035,6 +1033,5 @@ func (mc *mysqlConn) readBinaryRow(rc *mysqlRows) (*[]*[]byte, error) {
10351033
}
10361034
}
10371035

1038-
mc.affectedRows++
10391036
return &row, nil
10401037
}

0 commit comments

Comments
 (0)