Skip to content

float64 are not parsed properly when query is run with placeholders #433

Closed
@pib

Description

@pib

Here's a gist with minimal Go code and SQL demonstrating the issue: https://gist.github.com/pib/f8c9a4e153e6d226d2ee

When the data comes back in the no-placeholder version (which from #215, #211, #86 I see is different because it is run in text mode), the float value (which is a 32-bit float in MySQL) is parsed properly into a float64.

When the data comes back in the placeholder version, it is treated the same way as if strconv.ParseFloat(val, 32) was called demonstrated here: https://play.golang.org/p/HqWFhvYD31.

Switching to a float32 fixed the issue in my case, but this was a very confusing situation and it took a while to realize that it was caused by differences in behavior between queries with and without placeholders.

It seems like readRow (here: https://github.com/go-sql-driver/mysql/blob/master/packets.go#L1151) should be putting MySQL float types into a float32 instead of a float64 to prevent this situation.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions