doonbfez815298 2016-06-07 15:15
浏览 844
已采纳

golang sql驱动程序的prepare语句

With regards to golang's sql driver, what is the difference between the two statements below?

// store.DB is *sql.DB type
rows, err := store.DB.Query(SQL, args ...)
// err != nil
defer rows.Close()

and

// store.DB is *sql.DB type
stmt, err := store.DB.Prepare(SQL)
// err != nil
defer stmt.Close()

rows, err := stmt.Query(args ...)
// err != nil
defer rows.Close()

It seems that they are the same? Are there any subtle difference?

Update:

We don't need to perform many stmt.Exec or stmt.Query after db.Prepare, only one exec or query is performed after each prepare. And when we use db.Query or db.Exec, we pass arguments to the methods instead of using raw SQL string (for security consideration).

I have found one reference links: http://go-database-sql.org/prepared.html
It seems that both way are using prepared statement, what's the difference?

  • 写回答

2条回答

      报告相同问题?

      相关推荐 更多相似问题

      悬赏问题

      • ¥15 keil MDK软件进行仿真调试的局限
      • ¥15 关于gateway产生临时文件夹的问题
      • ¥15 Java Broken Pipe以及OOM
      • ¥20 请问有没有RTL8211FS的参考原理图
      • ¥30 esp32的platfromio工程添加文件就会编译失败
      • ¥15 linux下运行VASP报错
      • ¥15 python里面查找赋值,如何可以在剩余未空值的行里面进行进一步的筛选呢?
      • ¥15 电路分析的综合实验有没有会的
      • ¥15 #硬件设计#PNP三级管输出设计问题
      • ¥30 ORACLE的procedure突然需要重新编译是为什么?