This repository was archived by the owner on May 24, 2023. It is now read-only.
This repository was archived by the owner on May 24, 2023. It is now read-only.
retrieving.md: description of rows.Close() handling doesn't match with the code #70
Closed
Description
In Fetching Data from the Database, the explanatory text says Notice, however, that we check the error first, and only call rows.Close() if there isn't an error, in order to avoid a runtime panic.
; but this "check error and close if no error" isn't there in the code:
var (
id int
name string
)
rows, err := db.Query("select id, name from users where id = ?", 1)
if err != nil {
log.Fatal(err)
}
defer rows.Close()
for rows.Next() {
err := rows.Scan(&id, &name)
if err != nil {
log.Fatal(err)
}
log.Println(id, name)
}
err = rows.Err()
if err != nil {
log.Fatal(err)
}
I see only a defer rows.Close()
. Nowhere else is rows.Close()
called.
Metadata
Metadata
Assignees
Labels
No labels