Skip to content

Commit 9428023

Browse files
kardianosbradfitz
authored andcommitted
database/sql: add note to Scanner that the database owns values
It was unclear that users must copy values out of the src value for value types like []byte. Fixes #24492 Change-Id: I99ad61e0ad0075b9efc5ee4e0d067f752f91b8fa Reviewed-on: https://go-review.googlesource.com/108535 Reviewed-by: Brad Fitzpatrick <[email protected]>
1 parent 4122319 commit 9428023

File tree

1 file changed

+4
-0
lines changed

1 file changed

+4
-0
lines changed

src/database/sql/sql.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,10 @@ type Scanner interface {
301301
//
302302
// An error should be returned if the value cannot be stored
303303
// without loss of information.
304+
//
305+
// Reference types such as []byte are only valid until the next call to Scan
306+
// and should not be retained. Their underlying memory is owned by the driver.
307+
// If retention is necessary, copy their values before the next call to Scan.
304308
Scan(src interface{}) error
305309
}
306310

0 commit comments

Comments
 (0)