-
Notifications
You must be signed in to change notification settings - Fork 336
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
Expected way to convert MySQL floating point calculations? #481
Comments
MySqlConnector currently performs very few implicit conversions. This may be a bug; I'll need to extend AdoNetApiTest to examine what other providers generally do here. Note that SqlClient explicitly says:
But obviously there may be good reasons to be less strict for backwards compatibility with Connector/NET. I recommend sticking with the explicit |
Just to note - 100% compatibility with Connector/NET isn't good either. Just as an example - I actually found at least two cases in my code where I used If you ask me, then I think that MySqlConnector could perform fixed set of "safe" conversions, such as Then again, this should probably be an option to connection string, I'm very grateful for MySqlConnector being explicit in this regard and I'd rather use those explicit settings everywhere, even if meant casts in SQL queries, so thank you a lot for that. Since there is already similar issue in your repo for this case, I'll close this one and just reference it instead - mysql-net/AdoNetApiTest#4 Thank you a lot for answer! |
I'm executing SQL query which includes inside:
Since I'm not interested in absolute precision (I round it anyway), in original MySQL connector I used:
And that worked just fine, but after switching to your library I started getting in that place:
Now, I understand that I can always do
(float) dataReader.GetDecimal(0)
, which is in fact what I did, but I'm wondering if there is no better way to approach this issue. I'd expect that such conversion could be done in the library itself, but then again, maybe there is some way to declare precision of calculation or in other way point right away that we're not interested in using decimals? I didn't even know that under the hood there is a decimal used in the first place, so as an user it was weird to me that the library didn't do the conversion automatically, especially considering that it's possible with just a cast.Or maybe instead of all of that I should just use
CAST(... AS FLOAT)
in the SQL query itself?Thank you in advance for answer, as well as awesome work that you put into library in the first place, I love it! ❤️
The text was updated successfully, but these errors were encountered: