@@ -24,8 +24,8 @@ type mysqlField struct {
24
24
type rowsContent struct {
25
25
mc * mysqlConn
26
26
binary bool
27
- unread int
28
27
columns []mysqlField
28
+ eof bool
29
29
}
30
30
31
31
type mysqlRows struct {
@@ -47,7 +47,7 @@ func (rows mysqlRows) Close() (e error) {
47
47
}()
48
48
49
49
// Remove unread packets from stream
50
- if rows .content .unread > - 1 {
50
+ if ! rows .content .eof {
51
51
if rows .content .mc == nil {
52
52
return errors .New ("Invalid Connection" )
53
53
}
@@ -66,36 +66,38 @@ func (rows mysqlRows) Close() (e error) {
66
66
// when the dest type is know, which makes type conversion easier and avoids
67
67
// unnecessary conversions.
68
68
func (rows mysqlRows ) Next (dest []driver.Value ) error {
69
- if rows .content .unread > 0 {
70
- if rows .content .mc == nil {
71
- return errors .New ("Invalid Connection" )
72
- }
69
+ if rows .content .eof {
70
+ return io .EOF
71
+ }
73
72
74
- columnsCount := cap (dest )
73
+ if rows .content .mc == nil {
74
+ return errors .New ("Invalid Connection" )
75
+ }
75
76
76
- // Fetch next row from stream
77
- var row * []* []byte
78
- var e error
79
- if rows .content .binary {
80
- row , e = rows .content .mc .readBinaryRow (rows .content )
81
- } else {
82
- row , e = rows .content .mc .readRow (columnsCount )
83
- }
84
- rows .content .unread --
77
+ columnsCount := cap (dest )
85
78
86
- if e != nil {
87
- return e
79
+ // Fetch next row from stream
80
+ var row * []* []byte
81
+ var e error
82
+ if rows .content .binary {
83
+ row , e = rows .content .mc .readBinaryRow (rows .content )
84
+ } else {
85
+ row , e = rows .content .mc .readRow (columnsCount )
86
+ }
87
+
88
+ if e != nil {
89
+ if e == io .EOF {
90
+ rows .content .eof = true
88
91
}
92
+ return e
93
+ }
89
94
90
- for i := 0 ; i < columnsCount ; i ++ {
91
- if (* row )[i ] == nil {
92
- dest [i ] = nil
93
- } else {
94
- dest [i ] = * (* row )[i ]
95
- }
95
+ for i := 0 ; i < columnsCount ; i ++ {
96
+ if (* row )[i ] == nil {
97
+ dest [i ] = nil
98
+ } else {
99
+ dest [i ] = * (* row )[i ]
96
100
}
97
- } else {
98
- return io .EOF
99
101
}
100
102
101
103
return nil
0 commit comments