Skip to content
This repository was archived by the owner on Sep 7, 2021. It is now read-only.
This repository is currently being migrated. It's locked while the migration is in progress.

Commit f1b4f83

Browse files
authored
fix no rows return error when close (#1334)
1 parent d0827bf commit f1b4f83

File tree

2 files changed

+19
-11
lines changed

2 files changed

+19
-11
lines changed

rows.go

Lines changed: 3 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -113,17 +113,9 @@ func (rows *Rows) Close() error {
113113
defer rows.session.Close()
114114
}
115115

116-
if rows.lastError == nil {
117-
if rows.rows != nil {
118-
rows.lastError = rows.rows.Close()
119-
if rows.lastError != nil {
120-
return rows.lastError
121-
}
122-
}
123-
} else {
124-
if rows.rows != nil {
125-
defer rows.rows.Close()
126-
}
116+
if rows.rows != nil {
117+
return rows.rows.Close()
127118
}
119+
128120
return rows.lastError
129121
}

rows_test.go

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,22 @@ func TestRows(t *testing.T) {
3838
cnt++
3939
}
4040
assert.EqualValues(t, 1, cnt)
41+
assert.False(t, rows.Next())
42+
assert.NoError(t, rows.Close())
43+
44+
rows0, err := testEngine.Where("1>1").Rows(new(UserRows))
45+
assert.NoError(t, err)
46+
defer rows0.Close()
47+
48+
cnt = 0
49+
user0 := new(UserRows)
50+
for rows0.Next() {
51+
err = rows0.Scan(user0)
52+
assert.NoError(t, err)
53+
cnt++
54+
}
55+
assert.EqualValues(t, 0, cnt)
56+
assert.NoError(t, rows0.Close())
4157

4258
sess := testEngine.NewSession()
4359
defer sess.Close()

0 commit comments

Comments
 (0)