THIS IS A TEST INSTANCE ONLY! REPOSITORIES CAN BE DELETED AT ANY TIME!

Browse Source

fix no rows return error when close (#1334)

tags/v0.7.4
Lunny Xiao GitHub 4 months ago
parent
commit
f1b4f83684
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 19 additions and 11 deletions
  1. +3
    -11
      rows.go
  2. +16
    -0
      rows_test.go

+ 3
- 11
rows.go View File

@@ -113,17 +113,9 @@ func (rows *Rows) Close() error {
defer rows.session.Close()
}

if rows.lastError == nil {
if rows.rows != nil {
rows.lastError = rows.rows.Close()
if rows.lastError != nil {
return rows.lastError
}
}
} else {
if rows.rows != nil {
defer rows.rows.Close()
}
if rows.rows != nil {
return rows.rows.Close()
}

return rows.lastError
}

+ 16
- 0
rows_test.go View File

@@ -38,6 +38,22 @@ func TestRows(t *testing.T) {
cnt++
}
assert.EqualValues(t, 1, cnt)
assert.False(t, rows.Next())
assert.NoError(t, rows.Close())

rows0, err := testEngine.Where("1>1").Rows(new(UserRows))
assert.NoError(t, err)
defer rows0.Close()

cnt = 0
user0 := new(UserRows)
for rows0.Next() {
err = rows0.Scan(user0)
assert.NoError(t, err)
cnt++
}
assert.EqualValues(t, 0, cnt)
assert.NoError(t, rows0.Close())

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

Loading…
Cancel
Save