I need to make SQL queries to database in the loop:
for rows.Next() {
fields, err := db.Query(.....)
if err != nil {
// ...
}
defer fields.Close()
// do something with `fields`
}
What will be better: leave all as is or move defer
after loop:
for rows.Next() {
fields, err := db.Query(.....)
if err != nil {
// ...
}
// do something with `fields`
}
defer fields.Close()
Or something else ?
question from:
https://stackoverflow.com/questions/45617758/defer-in-the-loop-what-will-be-better 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…