-
Notifications
You must be signed in to change notification settings - Fork 2.3k
test and fix for MysSQL float parsing into float64 when placeholders are used #434
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
Merged
julienschmidt
merged 2 commits into
go-sql-driver:master
from
pib:fix_float_with_placeholder
Apr 11, 2016
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unfortunately the driver spec does not allow to return a float32 as a driver.Value: https://golang.org/pkg/database/sql/driver/#Value
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Huh, it's strange that it works anyway. I suppose what the spec says and the details of the implementation vary a bit.
Looking through some of the standard library sql code, I see that they seem to work around this issue by converting floats to strings and back using strconv.ParseFloat with the bit size of the field it is going into: https://golang.org/src/database/sql/convert.go#L256
Actually, that function is called by sql.Rows.Scan, which means that their spec for Value is actually inaccurate: https://golang.org/src/database/sql/sql.go#L1849
It seems that the doc for driver.Rows https://golang.org/pkg/database/sql/driver/#Rows should be updated to specify that they do handle more types, including float32.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I suppose I will submit a ticket to the golang project asking for clarification.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If it works and we have proper tests for it, I would be fine with ignoring the specification (which is rather flawed anyway). We're testing against all Go versions and tip, so we would notice if it breaks in a future version.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, this change fixes the issue I was running into and the tests I added cover both cases and passed on Travis.
I added an issue to the Go repo so they will hopefully fix the documentation to include the full list of types that are actually allowed in returns from drivers.