Skip to content

Commit

Permalink
fix(rows): doesn't close rows on Scan
Browse files Browse the repository at this point in the history
  • Loading branch information
cnlangzi committed Dec 11, 2024
1 parent c243137 commit 5a84b47
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 1 deletion.
1 change: 0 additions & 1 deletion rows.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ func (r *Rows) Close() error {
}

func (r *Rows) Scan(dest ...any) error {
defer r.Close()
return r.Rows.Scan(dest...)
}

Expand Down
34 changes: 34 additions & 0 deletions rows_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,40 @@ func TestRowsBind(t *testing.T) {
name string
run func(t *testing.T)
}{
{
name: "scan_on_rows_should_work",
run: func(t *testing.T) {
type user struct {
ID int
Status int
Email string
Passwd string
Salt string
Created *time.Time
}
rows, err := db.Query("SELECT id,email FROM rows WHERE id<4")
require.NoError(t, err)

var id int
var email string

err = rows.Scan(&id, &email)
require.NoError(t, err)
require.Equal(t, 1, id)
require.Equal(t, "[email protected]", email)

err = rows.Scan(&id, &email)
require.NoError(t, err)
require.Equal(t, 2, id)
require.Equal(t, "[email protected]", email)

err = rows.Scan(&id, &email)
require.NoError(t, err)
require.Equal(t, 3, id)
require.Equal(t, "[email protected]", email)

},
},
{
name: "bind_slice_of_struct_should_work",
run: func(t *testing.T) {
Expand Down

0 comments on commit 5a84b47

Please sign in to comment.