Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Should we also close DB's .Prepare() in Golang?

From this tutorial shown that rows.Closed() must be called where rows is from stmt.Query(), is stmt.Closed() also should be called where stmt is from db.Prepare()?

// inside a function
stmt, err := db.Prepare(cmd) // cmd is SQL string
Check(err)
// should we add: defer stmt.Close()
rows, err := stmt.Query(params) // params is map/interface{}
defer rows.Close()
Check(err)
like image 542
Kokizzu Avatar asked Oct 22 '25 06:10

Kokizzu


1 Answers

The short answer is Yes. You should call stmt.Close();

The long answer can be found in this google groups thread.

like image 177
joshua Avatar answered Oct 23 '25 21:10

joshua



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!