reactor  

RE: [Reactor for CF] boolean vlaues in mysql

Chris Blackwell
Fri, 10 Nov 2006 10:26:38 -0800

Heres some sample code that demonstrates the problem i have..
 
CREATE TABLE `Test` (
  `TestId` int(10) unsigned NOT NULL auto_increment,
  `Active` tinyint(1) NOT NULL,
  PRIMARY KEY  (`TestId`)
)
 
<cfset test = reactor.createRecord("Test")>
<cfset test.setActive(true)>
<cfset test.validate()>
<cfdump var="#test._getErrorCollection().getErrors()#">
 
Results in a Test.Active.invalidType.
 
This result is totally expected, as Reactor has to validate a TINYINT as numeric by default.  Obviously it's no problem to use 1/0 when hard coding the values, but i ran into the problem when processing a checkbox for an object like this.
<cfset user.setActive(structkeyexists(form, "active"))>
 
You can pass in "true" or "false" to the record and save it because in MySQL True/False are just synonyms for 1/0 and get converted internally (Try SELECT true + 0).  You just can't validate it "out of the box" with the default validator.
 
For now overriding the setter will do the job
 
 <cffunction name="setActive" access="public" output="false" returntype="void">
  <cfargument name="Active" type="boolean" required="yes">
  <cfset super.setActive(iif(arguments.Active, 1, 0))>
 </cffunction>
 
 


From: [EMAIL PROTECTED] [mailto:[EMAIL PROTECTED] On Behalf Of Dave Shuck
Sent: 10 November 2006 17:28
To: reactor@doughughes.net
Subject: Re: [Reactor for CF] boolean vlaues in mysql

We just set the column type to BOOLEAN in MySQL 5 (although it later magically becomes TINYINT(1)), and pass ColdFusion boolean values with no issues whatsoever.

~Dave

On 11/10/06, Chris Blackwell <[EMAIL PROTECTED]> wrote:

How are people representing boolean values in mysql (4 or 5) with
reactor?  I've always used TINYINT(1) but with reactor its causing a
problem because, by default, it validates the field as numeric so I get
an invalidType error.

I've tried the BIT(1) datatype for MySQL5, but CF can't convert the
value to a boolean, I'm actually not sure what this returns now, it used
to be a synonym for TINYINT(1).
BOOL/BOOLEAN are converted to TINYINT(1) by MySQL so those type are
useless, the mysql ObjectDAO will never see this type.

For now I'm overriding the setColumn(bool) to convert the boolean to 1/0
and call super.setColumn(int).

I've only just run into this issue as I've started using Reactors
validation instead of my own.

Chris Blackwell
Web Developer

Telephone: +44 (0)117 373 1465
Email: [EMAIL PROTECTED]

This email is intended for the use of the named recipient(s) only. Any
information contained within this message or any of its attachments may
be confidential and privileged information.  Any unauthorized
disclosure, reproduction, distribution or other dissemination or use of
this communication is strictly prohibited.



-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
Reactor for ColdFusion Mailing List
reactor@doughughes.net
Archives at: http://www.mail-archive.com/reactor%40doughughes.net/
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --




--
~Dave Shuck
[EMAIL PROTECTED]
www.daveshuck.com

Where's your Spot?
www.instantspot.com
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
Reactor for ColdFusion Mailing List
reactor@doughughes.net
Archives at: http://www.mail-archive.com/reactor%40doughughes.net/
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --

-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --
Reactor for ColdFusion Mailing List
reactor@doughughes.net
Archives at: http://www.mail-archive.com/reactor%40doughughes.net/
-- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- -- --