我们还应该在Golang中关闭DB的.Prepare()吗? [英] Should we also close DB's .Prepare() in Golang?
本文介绍了我们还应该在Golang中关闭DB的.Prepare()吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
来自此教程显示必须在rows
来自stmt.Query()
的地方调用rows.Closed()
,是stmt.Closed()
还是在stmt
来自db.Prepare()
的地方调用?
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)
推荐答案
简短的回答是是".您应该致电stmt.Close();
The short answer is Yes. You should call stmt.Close();
长答案可在此Google网上论坛线程中找到.
The long answer can be found in this google groups thread.
这篇关于我们还应该在Golang中关闭DB的.Prepare()吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文