mysql icon indicating copy to clipboard operation
mysql copied to clipboard

sql.ScanType Type error for nullable uint64

Open quanqqqqq opened this issue 1 year ago • 5 comments

Issue description

Tell us what should happen and what happens instead

Example code

when field type bigint(20) unsigned null, this code will return scanTypeNullInt, it can't read uint64 data such 18446744073709551615. https://github.com/go-sql-driver/mysql/blob/master/fields.go#L174 image

Error log

image

Configuration

Driver version (or git SHA): 1.7.1 Go version: run go version in your console 1.18 Server version: E.g. MySQL 5.6, MariaDB 10.0.20 5.7 Server OS: E.g. Debian 8.1 (Jessie), Windows 10 Debian 8.1

quanqqqqq avatar May 22 '23 13:05 quanqqqqq

database/sql doesn't provide sql.NullUInt64. What other drivers do?

methane avatar May 22 '23 14:05 methane

@methane https://github.com/ClickHouse/clickhouse-go/blob/aa43e908d734a38cea2dcfba4b898ddea9f35c66/lib/column/codegen/column.tpl#LL59C10-L59C10

like clickhouse, it will return big.Int when field greater than int64

quanqqqqq avatar May 22 '23 15:05 quanqqqqq

I don't want to use Big. NullUInt64 is better, but I hope database/sql provide it.

methane avatar May 23 '23 16:05 methane

https://github.com/golang/go/issues/47953

methane avatar May 23 '23 16:05 methane

golang/go#47953 was rejected and closed. Now I proposed https://github.com/golang/go/issues/60370

methane avatar May 23 '23 17:05 methane

sql.Null[T] will be in Go 1.22.

dolmen avatar Oct 17 '23 21:10 dolmen

I won't add it in this driver.

Please copy&paste the sql.Null[T] from Go 1.22 into your application until you can use Go 1.22. ("A little copying is better than a little dependency.")

methane avatar Oct 19 '23 07:10 methane