-
Notifications
You must be signed in to change notification settings - Fork 18k
database/sql: Scanner.Scan requires bytes to be copied #24492
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
This is a potential fix, I'm happy to put up a PR if we like it.
This adopts the approach of making the code behave the same as the later cases, e.g.:
|
/cc @kardianos |
@awreece I could see this as a documentation update. I'm skeptical about changing this code though. If we add clone bytes, other scan implementations would start copying it twice. |
Fair enough. I personally prefer the consistency of " |
Change https://golang.org/cl/107995 mentions this issue: |
Change https://golang.org/cl/108535 mentions this issue: |
Its possible this is a doc change to sql.Scanner.Scan to reflect the expectations of sql.Scanner.Scan; it would be slightly nicer to copy src byte slices before passing them to sql.Scanner.Scan to avoid such surprises.
What version of Go are you using (
go version
)?go version go1.10 darwin/amd64
Does this issue reproduce with the latest release?
Yes
What did you do?
What did you expect to see?
I expected the test to pass; from the docs on sql.Scanner, I assumed I could just assign the source to my destination. Digging a bit deeper, it looks like
convertAssign
makes a deep copy of dest viacopyBytes
whensrc
is a primitive; but it doesn't do so when using theScanner
interface:https://golang.org/src/database/sql/convert.go#L340
My guess is this violates the expectations of
Rows.Scan
`:What did you see instead?
The text was updated successfully, but these errors were encountered: