Regression in 1.8.0 with Scan method and custom types
matejsp opened this issue · 2 comments
Issue description
We have market field defined as SMALLINT. However we read this into string field. Why we do that is because we are reading directly into externally defined struct and it expects string. However this string is defined as new type.
Calling Scan works if the field is defined as string ... but not if defined as custom string type.
In 1.7.1 it worked for both cases (string and type X string). But since 1.8.0 it errors in the Scan call.
Example code
type SomeStringField string
rows, err := s.db.Query(`SELECT id, market FROM mylogtable;`)
s.Require().NoError(err)
s.True(rows.Next())
var logId int64
var somestringfield SomeStringField
err = rows.Scan(&logId, &somestringfield)
s.Require().NoError(err)Error log
Error:
Received unexpected error:
sql: Scan error on column index 3, name "market": unsupported Scan, storing driver.Value type int64 into type *database.SomeStringField
Configuration
Driver version (or git SHA):
1.8.1 -> regression
1.8.0 -> regression
1.7.1 -> OK
Go version: go version go1.23.2 darwin/arm64
Server version: MySQL 8.0.36
Server OS: Amazon Linux 2023, tested on MacOSX 14.7
It is expected behavior change, not a regression.
You should use some conversion layer instead of using database/sql directly.
Can you please point me to the release notes stating that change? I couldn't find it and the reasoning behind it.