O'Reilly logo

Go Standard Library Cookbook by Radomir Sohlich

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

How it works...

To create the prepared statement, the Prepare method of the pointer to the DB struct needs to be called. After this, the Exec or Query method on the Stmt pointer is called with given parameters for the statement.

The prepared statement is created within the scope of the DB pointer, but on the specific connection from the connection pool. The statement remembers which connection has been used, and when it is invoked, it tries to use the same connection. If the connection is busy or was closed, then it recreates the prepared statement and calls the statement on a new connection.

The situation changes if you use the prepared statement within an opened transaction *Tx, in this case, the prepared statement is bound to one connection ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required