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.

Posted by roy on February 1, 2008 at 02:01 PM in Web Development | 3 Comments

Related Entries

Linked Entries

These are Tabulas entries which have linked to this particular entry.

Want to comment with Tabulas?. Please login.

Guilherme (guest)

Comment posted on June 22nd, 2010 at 01:57 PM
Dude, you should try and use tinyint(3) instead. Worked out for me. tinyint(1) is parsed as bool by C#, but tinyint(3) is byte.

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)

Comment posted on October 28th, 2008 at 10:07 AM
Thats shocking.
Comment posted on February 4th, 2008 at 11:28 AM
n00b.