Closing Prepared Statement In Transaction


I’m using Golang’s sql/database driver. I close statement before i commit my transaction, in another function. I was wondering if there is any issue with this.

To be clear, I have tried this and it works. The database is successfully updated, and I don’t see any problems. I’m just curious if there is any possible potential problem that I am unaware of.


I understand that Prepare() allows the database to allocate resources for the preparation and returns a handler on the resources. Then, execute passes in parameters if any, along with the handler ID.

What I would like to confirm is, when you execute, does the transaction pick up the necessary information, so that the user is free to deallocate the Prepare resources without any side-effects?
---- example ----

func main() {
tx, _ = sql.Begin()

func handleMyStuff(tx *sql.Tx) {
stmtIn, _ := tx.Prepare(“sql statement here”)

The statements prepared for a transaction by calling the transaction’s Prepare or Stmt methods are closed by the call to Commit or Rollback.

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.