February 1, 2008
tinyint(1) is a boolean!
Last night, we tried to upgrade Wik.is. And things broke. Things that shouldn't have broken, broke. Pete narrowed it down to C#'s mysql.data.dll...
Max found the changelog with this innocuous comment:
fixed code where we were returning bit(1) as boolean but mysql treats tinyint(1) as boolean (bug #27959)
Uh, what? So we check out the bug report:
When using MySqlDataAdapter to fill a DataTable from a query, boolean field are not returned as System.Boolean. Them are returned as integer.
I've searched the bugs database, and I found only a workaround: use Convert.ToBoolean to returned field.
The problem is that I use column type to synchronize two different databases and one of them is not MySql. In this way I cannot establish if MySql field is truly boolean or is integer instead.
With MySqlConnection.GetSchema("DataTypes") I've found that System.Boolean there is not on mapped datatypes. Probably is that the cause of problem.
(snip repro)
Add a column mapping on the connector for tinyint(1) => System.Boolean
So basically, some lazy dev didn't want to write code adapting his personal need for booleans in mySQL and overloaded tinyint(1) into a boolean column.
Never mind the people who used tinyint(1) to store any values other than 0 and 1... oh no! Screw them! Nobody would dare store any values between -128 to 127, or 0 to 255 in a tinyint(1)! Simone Giordano thinks we should make it a bool!
Awesome.
Comment with Facebook
Want to comment with Tabulas?. Please login.
Guilherme (guest)
The number inside the parameters is not the length, since you can store number up to 127 with tinyint(3).
I tried smallint(1) but it still uses 2 bytes, hence wasting precious space.
Good luck!
charlie (guest)
hapy