-
Notifications
You must be signed in to change notification settings - Fork 18k
database/sql: Scan results are of wrong type when Query has no args #27828
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
CC @kardianos |
Please try to use https://godoc.org/bitbucket.org/kardianos/table and see if this persists. Also what driver are you using, and version? |
See the PoC: No idea what version, I presume the latest, since I don't specify any version. |
Believe this is mysql driver specific. The two queries use different mysql protocols, first one requires preparing (as is parameterized and DSN setting interpolateParams is false) so uses mysql's binary protocol. Second is simpler (without parameters) so uses text protocol. If add interpolateParams=true to the DSN, the output of the two queries becomes consistent, as only text protocol will be used. Both returning the []uint8: []byte{0x31, 0x32, 0x33} (aka "123"). |
This sounds correct. Please file an issue in the driver. |
I made an issue in the driver, and they claim it's expected behaviour: go-sql-driver/mysql#861 I understand the reasoning, but the end result is that as a user of this library I need to be aware of implementation details of the driver, which is less than ideal. |
Yes, I find that behavior troubling as well. But then, it is MySQL...
…On Fri, Sep 28, 2018, 04:15 ComaVN ***@***.***> wrote:
I made in issue in the driver, and they claim it's expected behaviour:
go-sql-driver/mysql#861
<go-sql-driver/mysql#861>
I understand the reasoning, but the end result is that as a user of this
library I need to be aware of implementation details of the driver, which
is less than ideal.
—
You are receiving this because you modified the open/close state.
Reply to this email directly, view it on GitHub
<#27828 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AAuFsZCpGhUkK1OJUDl7UjY_pRRCLo-iks5ufgTFgaJpZM4W2rlq>
.
|
Should be noted that the return type does depend on the value, irrespective of driver. If replace 123 with 18446744073709551615 (MaxUint64) in the above code, database/sql Scan() is not going to return an uint64 type but a string using &interface{}s. |
This is again true for MySQL. This would not be true for other databases. |
It's true for github.com/denisenkom/go-mssqldb. I just tested it :) Meaning both queries on mssql return and not an uint64 value. |
What version of Go are you using (
go version
)?go version go1.11 linux/amd64
Does this issue reproduce with the latest release?
Yes
What operating system and processor architecture are you using (
go env
)?What did you do?
I tried to use Rows.Scan to read fields of an sql result row into variables of type
interface{}
See https://github.com/ComaVN/gosqltypespoc
What did you expect to see?
I expect integer sql types to be read as go type
int64
, or at least, the go type should be the same whatever the query looks like.What did you see instead?
SELECT 123 WHERE ? = 1
returnsint64: 123
SELECT 123 WHERE 1 = 1
returns[]uint8: []byte{0x31, 0x32, 0x33}
The text was updated successfully, but these errors were encountered: