On Jul 17, 12:35 pm, AD7six <andydawso...@gmail.com> wrote: > On Jul 16, 6:19 pm, Dérico Filho <uldericofi...@gmail.com> wrote: > > > Hi > > > Some of you might feel bugged when trying to access an TINYINT(1) > > field in mysql with values different from 0 or 1. > > > It happens that CakePHP thinks TINYINT(1) is BOOLEAN. > > Look at the definition of what a BOOLEAN > is:http://dev.mysql.com/doc/refman/5.0/en/numeric-type-overview.html > > e.g.http://pastebin.com/9QF6Ecun
Well... The canonical definition of boolean stands for TRUE and FALSE. Actually BOOLEAN is something, conceptually, bigger than MySQL. http://en.wikipedia.org/wiki/Boolean_data_type As MySQL did NOT, as of 5.0.SOMETHING, have the most near datatype for BOOLEAN which is BIT, they shortcut it to TINYINT(1). Which, by definition IS NOT boolean, as it may store integer numbers up to 2^8 or 2^7 plus sign bit (-/+). I particularly used, up to emerge of BIT datatype, TINYINT(1) to store up to 10 different status of something. 0 - means X, 1 - means Y and so forth. Either INT(1) or TINYINT(2), which workarounds the problems, are fine. I just wanted to pointed this behaviour somewhere so as to avoid confusion. It is NOT documented in CakePHP docs. Nowhere. No fix requested. Thanks Anyway, > > Therefore, 0 is > > 0/False and anything else but zero is 1/TRUE. > > > If it ever happens to you, you have two options. > > > First, you may change the field type to INT(1) -- which will wok > > although it might change the way MySQL handle data. > > Personally I use TINYINT(2). > > > > > Second, you may dike out the lines: > > if (($col == 'tinyint' && $limit == 1) || $col == > > 'boolean') { > > return 'boolean'; > > } > > AND > > 'boolean' => array('name' => 'tinyint', 'limit' => '1') > > > From cake/libs/model/datasources/dbo/dbo_mysql*.php > > Your fix just breaks things the other way around - what if you /do/ > have a TINYINT(1) which you want to have yes/no stored in it. > > hth, > > AD Check out the new CakePHP Questions site http://cakeqs.org and help others with their CakePHP related questions. You received this message because you are subscribed to the Google Groups "CakePHP" group. To post to this group, send email to cake-php@googlegroups.com To unsubscribe from this group, send email to cake-php+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/cake-php?hl=en