On Oct 8, 10:48 am, Taavi Burns <taavi.bu...@gmail.com> wrote: > On Oct 8, 9:58 am, "goo...@venix.com" <goo...@venix.com> wrote: > > >http://www.google.com/url?sa=D&q=http://groups.google.com/group/sqlal... > > > I had grumbled that mapping tinyint(1) to bool was an issue for people > > who were simply trying to process small integers. I had no idea that > > some people used that as a convention for indicating a boolean field > > in MySQL. > > > Since 1 == True and 0 == False, an integer field will behave like a > > bool for people who simply code with boolean values. > > Well, as the other thread stated, if you ask MySQL for a bool, you get > a TINYINT(1) back, which isn't precisely the same as a default
The (1) simply means to display a single digit by default. (4) allows for 3 digits and a minus sign. The tinyint(x) has no impact on the processing. tinyint is simply 8 bits. MySQL does not provide a type- enforced boolean column. > TINYINT: > > mysql> create table foo (a bool, another tinyint); > Query OK, 0 rows affected (0.00 sec) > > mysql> show create table foo\G > *************************** 1. row *************************** > Table: foo > Create Table: CREATE TABLE `foo` ( > `a` tinyint(1) default NULL, > `another` tinyint(4) default NULL > ) ENGINE=MyISAM DEFAULT CHARSET=latin1 > 1 row in set (0.00 sec) I got burned by the old force a boolean behavior because I had been using the display width values as a convenient way to size a column without having to first scan the values to determine the needed column width. I had know idea that single digit values would be forced into 0 or 1 when saved through the orm. I understand this is a real nuisance for Michael Bayer and the developers. Still when reflecting a MySQL table, there is no way to know if the original field definition was bool or tinyint(1). Defaulting to a boolean column type changes the behavior from the actual MySQL behavior of accepting any 8 bit value. > But as I said, it's not a big deal for me, since we can handle it > cleanly in the translation to base declarative. I guess I should > submit a changeset for the docs to clarify the new behaviour then. > > And yes, we end up throwing this data into JSON, so we really do want > it coerced to a Python boolean ASAP. :) -- You received this message because you are subscribed to the Google Groups "sqlalchemy" group. To post to this group, send email to sqlalch...@googlegroups.com. To unsubscribe from this group, send email to sqlalchemy+unsubscr...@googlegroups.com. For more options, visit this group at http://groups.google.com/group/sqlalchemy?hl=en.