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 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access