-
Notifications
You must be signed in to change notification settings - Fork 183
retrieving.md: description of rows.Close() handling doesn't match with the code #70
Comments
That is perfectly ok. |
I am aware of how |
I'm sorry if I missed something, but (comments added): rows, err := db.Query("select id, name from users where id = ?", 1)
// check error
if err != nil {
// error, log and terminate, no Close
log.Fatal(err)
}
// no error, Close when function ends
defer rows.Close() To me, that looks exactly like |
Ok I see. I get it now, sorry about that. I was reading that point as if it was relating to code after the |
As I'm [not the only one](VividCortex#70) who stumbled upon this, let's just add a comment to the example code. No logging library I have worked with goes as far as terminating the program, so many go beginners may not understand this - although I think it does make sense. (Otherwise - what's the meaning of "fatal"?)
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:I see only a
defer rows.Close()
. Nowhere else isrows.Close()
called.The text was updated successfully, but these errors were encountered: