Skip to content

Commit a9ece60

Browse files
committed
Merge pull request #103 from go-sql-driver/rows
Small refactoring in rows.go
2 parents 87f2050 + 7aa2b6a commit a9ece60

File tree

2 files changed

+6
-9
lines changed

2 files changed

+6
-9
lines changed

errors.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ import (
1717
)
1818

1919
var (
20+
errInvalidConn = errors.New("Invalid Connection")
2021
errMalformPkt = errors.New("Malformed Packet")
2122
errNoTLS = errors.New("TLS encryption requested but server does not support TLS")
2223
errOldPassword = errors.New("It seems like you are using old_passwords, which is unsupported. See https://github.com/go-sql-driver/mysql/wiki/old_passwords")

rows.go

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ package mysql
1111

1212
import (
1313
"database/sql/driver"
14-
"errors"
1514
"io"
1615
)
1716

@@ -37,33 +36,30 @@ func (rows *mysqlRows) Columns() (columns []string) {
3736
}
3837

3938
func (rows *mysqlRows) Close() (err error) {
40-
defer func() {
41-
rows.mc = nil
42-
}()
43-
4439
// Remove unread packets from stream
4540
if !rows.eof {
4641
if rows.mc == nil {
47-
return errors.New("Invalid Connection")
42+
return errInvalidConn
4843
}
4944

5045
err = rows.mc.readUntilEOF()
5146
}
5247

48+
rows.mc = nil
49+
5350
return
5451
}
5552

56-
func (rows *mysqlRows) Next(dest []driver.Value) error {
53+
func (rows *mysqlRows) Next(dest []driver.Value) (err error) {
5754
if rows.eof {
5855
return io.EOF
5956
}
6057

6158
if rows.mc == nil {
62-
return errors.New("Invalid Connection")
59+
return errInvalidConn
6360
}
6461

6562
// Fetch next row from stream
66-
var err error
6763
if rows.binary {
6864
err = rows.readBinaryRow(dest)
6965
} else {

0 commit comments

Comments
 (0)