From 55dba87458542cb631baac80aeea0c3607d8f421 Mon Sep 17 00:00:00 2001 From: Justin Li Date: Wed, 23 Jan 2019 09:55:56 -0500 Subject: [PATCH] database/sql: document Stmt lifetime --- src/database/sql/sql.go | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/src/database/sql/sql.go b/src/database/sql/sql.go index 38a173adba..8cdc903c68 100644 --- a/src/database/sql/sql.go +++ b/src/database/sql/sql.go @@ -2256,6 +2256,13 @@ var ( // Stmt is a prepared statement. // A Stmt is safe for concurrent use by multiple goroutines. +// +// If a Stmt is prepared on a Tx or Conn, it will be bound to a single +// underlying connection forever. If the Tx or Conn closes, the Stmt will +// become unusable and all operations will return an error. +// If a Stmt is prepared on a DB, it will remain usable for the lifetime of the +// DB. When the Stmt needs to execute on a new underlying connection, it will +// prepare itself on the new connection automatically. type Stmt struct { // Immutable: db *DB // where we came from