-
Notifications
You must be signed in to change notification settings - Fork 333
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
Can't convert Bool to Int32 (TINYINT) #782
Comments
…l-net#782) Signed-off-by: Daniel Cohen Gindi <danielgindi@gmail.com>
No, but
It can hold values from -128 to 127. You didn't add any tests for the new code (to compare against Connector/NET), but it seems like this PR could lead to data loss (coercing all non-zero values to 1).
Can you provide more details about your use case? Why do you have |
Connector/NET exhibits the same behaviour (changing all non-zero values to |
@bgrainger What I implemented will produce the same result as Connector/NET. As for the use case - does it matter? Also this happens with |
And same goes for |
I'm not sure what you're referring to. Tests for |
It is drop-in for many common scenarios, but does deliberately make breaking API changes to fix bugs in (or make improvements to) Connector/NET's behaviour.
Yes; I'd like to understand it better to decide whether it's reasonable (IMO) for a breaking change to occur in this code path or not. |
Agreed, so I added Boolean->X conversions to my ADO.NET tests. You can walk through the results by searching for SqlClient (all versions), npgsql, and MySqlConnector don't permit an implicit conversion from Boolean to int (or any other data type). Moreover, while The pattern of this library has generally been to follow ADO.NET best practices, not to reproduce every Connector/NET bug; hence I'm still interested in learning more about the use case for this behaviour change. |
Sorry, my mistake. Indeed |
Okay so I've found instances in the code (our codebase) where a programmer casted from a |
I've checked this, and If someone wanted to store bits, like 1/0 columns, that have no Also it's a bit weird to me that you can You do not have to agree with me, but these are just some points for consideration :-) |
There are two ways to accomplish this: use
You can already get a (I understand it may be confusing that Thanks for your patience in this discussion; I'm agreeing that it's reasonable (particularly for backwards compatibility with Connector/NET, and symmetry with calling |
Yes I see the issue with other RDBMSs having a bool type and then it makes absolutely no sense to fetch as an int (unless you are a c++ programmer, or even a VB programmer that expects it to be equal to 0/-1 which is incompatible with anything). In MySql I feel there are too many aliases. I think that they could have treated And yeah I have a lot of patience, we are locked at home and my girls are climbing on me, so you know either way you leave this event with lots of patience... |
Allow reading `bool` as integer, like `MySql.Data` allows (Fixes #782)
Fixed in 0.63.0. |
With Oracle's
MySql.Data
, when you read a TINYINT column - you can read it as abool
or as anInt32
- either way works.And it only makes sense as
TINYINT
is not explicitly a boolean, it's just so tiny that it can only hold 0 or 1... And it's called TINYINT.Seems like an easy fix.
It currently throws:
Can't convert Bool to Int32
From:
MySqlConnector\Core\Row.cs:line 224
For me - this was an unexpected breaking change when trying the transition to this library.
The text was updated successfully, but these errors were encountered: