英文:
Retrieving Values From a Prepared Statement and Select Query in Go
问题
我不确定如何从预处理语句中检索值,因为结果只返回有关事务的信息。
statement, err := txn.Prepare(`SELECT id, password FROM public.user WHERE email = $1`)
result, err = stmt.Exec(email, password, email)
我了解Query()和QueryRow()具有预期的结果,但据我了解,它们是不安全的。对此的任何帮助将不胜感激,谢谢。
英文:
I'm unsure how to retrieve values from a prepared statement since result only returns information about the transaction.
statement, err := txn.Prepare(`SELECT id, password FROM public.user WHERE email = $1`)
result, err = stmt.Exec(email, password, email)
I understand Query() and QueryRow() have the intended result, but from what I understand, they are unsafe. Any help on this is appreciated, thanks.
答案1
得分: 3
以下是翻译好的内容:
它们非常安全,使用方式相同,exec 实际上只是用于插入操作:
stmt, err := txn.Prepare(`SELECT id, password FROM public.user WHERE email = $1`)
rows, err := stmt.Query(email)
请查看:https://code.google.com/p/go-wiki/wiki/SQLInterface
英文:
They are perfectly safe, you use it the same way, exec is really just for inserts:
stmt, err := txn.Prepare(`SELECT id, password FROM public.user WHERE email = $1`)
rows, err := stmt.Query(email)
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论