Search Blog

Recent Comments
Re: Stats plugin ported to Model-Glue (by J.mihai at 12/14 8:52 AM)
Re: CFC DAO Generator (by rui at 7/04 5:42 AM)
Re: Updates to the DAO, Bean and Gateway generator (by rui at 7/04 4:49 AM)
Re: CFC DAO Generator (by fwscott at 6/22 7:03 PM)
Re: CFC DAO Generator (by dan at 6/22 12:38 PM)
Re: Trip to Thailand (by fwscott at 3/27 2:10 AM)
Re: CFC DAO Generator (by fwscott at 3/27 2:03 AM)
Re: CFC DAO Generator (by Garry Harstad at 3/26 12:30 PM)
Re: Trip to Thailand (by Niqui Merret at 3/23 4:51 PM)
Re: Adding a blogger ping utility to BlogCFM (by fwscott at 2/20 9:01 PM)
Categories
Annoucements (1 entries)
BlogCFM (3 entries)
CFC Generator (5 entries)
Coldfusion (11 entries)
Fusebox (2 entries)
Greasemonkey (1 entries)
Misc (3 entries)
Archives
November 2005 (2 entries)
October 2005 (1 entries)
August 2005 (1 entries)
July 2005 (4 entries)
June 2005 (5 entries)
May 2005 (7 entries)

Powered by
BlogCFM v1.01

June 2005
Faking a null value
Post a Comment
The more and more I am generating code with the CFC Bean, DAO and gateway creator

The more I am noticing the need to support a null value and I am trying not to go in and write work arounds for each bean / dao / gateway CFCs to support nulls.

So, would defining a default bogus null value per bean be the way to go?

Example:
<cfcomponent displayname="myBean" hint="I model a single myBean.">

    <cfset variables.NumericNull = -99999 />
    <cfset variables.StringNull = "null" />
    <cfset variables.DateNull = CreateDate(1877,01,01) />
    <cfset variables.BinaryNull = toBinary(toBase64("null")) />

Now in the DAOs have something like:
    <cffunction name="update" returntype="void" output="false" hint="CRUD method">
        <cfargument name="myBean" type="myBean" required="true" />   
        <cfset var myBeanUpdate = 0 >
        <cfset var numericNull = arguments.myBean.getNumericNull() />
        <cfset var DateNull = arguments.myBean.getDateNull() />
        <cfset var StringNull = arguments.myBean.getStringNull() />
        <cfset var BinaryNull = arguments.myBean.getBinaryNull() />

        <cfquery name="myBeanUpdate" datasource="#variables.dsn#" >
            UPDATE myBean
            SET
               myBeanValue1 =
                <cfif arguments.myBean.getmyBeanValue1() NEQ stringNull>
                     <cfqueryparam cfsqltype="cf_sql_vchar" value="#arguments.myBean.getmyBeanValue1()#" maxlength="10" />
                <cfelse>
                     <cfqueryparam cfsqltype="cf_sql_vchar" null="yes" />
                </cfif>
            WHERE
                   id = <cfqueryparam cfsqltype="cf_sql_integer" value="#arguments.myBean.getmyBeanID()#" />       
        </cfquery>
    </cffunction>

I uploaded new transforms to the demo CFC Creator script to reflect these changes if you want to see how a fully generated CFC looks using the above.

Thoughts?

Think I should use the new transforms in the downloadable version of CFC Creator?
Posted by fwscott at 3:19 PM | Comments (5)
 
Subscription Options

You are not logged in, so your subscription status for this entry is unknown. You can login or register here.

Re: Faking a null value
nice work.... nothing like generating code from the db!

I think adding the null support to the bean object would be nice.... add an optional second parameter to the set methods, isnull which defaults to false

and then rewriting the cfqueryparam's so there is only one and the null="arguments.myBean.isNullValue1()"

this is more explict as CF doesn't have nulls and different db's treat null differently.. ms sql treats an empty string as null unlike oracle which treats the two differently

Posted by zac spitzer on June 9, 2005 at 8:56 PM

Re: Faking a null value
I really like that idea. I rewrote the current XSL to use the suggestions. Only bad thing is I had to do my own type checking in set functions because I have to allow anything to be thrown in as an argument to a set{paramname}() now.

But the above changes really makes the code cleaner.

Take a look at the demo to see the changes.

Posted by fwscott on June 9, 2005 at 10:25 PM

Re: Faking a null value
Really great stuff - but... cfccreator does not seem to be able to detect the primary keys on my microsoft SQL 2000 databases. Bummer...

Posted by Hilary Bridel on June 11, 2005 at 9:32 AM

Re: Faking a null value
Hilary,

I just found out about this the other day... I am gonna have to load up a version of MS SQL and try to figure out what is going on.

For now, a Dany Lamberge gave me a workaround... Around line 160 in table.cfc, change to: <!--- <cfif isnumeric(indexqry.non_unique)> ---> <cfset comparestrprimary = "'0'"> <cfset comparestrnonprimary = "'1'"> <!--- <cfelse> <cfset comparestrprimary = "'false'"> <cfset comparestrnonprimary = "'true'"> </cfif> ---> Notice the 0 and 1 have a single quote around them.

It appears the JDBC driver returns a string of 0 or 1 for MS SQL instead of a number.

Would also love to hear a suggestion for a fix for this without having to check by database type.

Posted by fwscott on June 11, 2005 at 11:23 AM

Re: Faking a null value
That workaround does not seem to work for me.

Posted by Hilary on June 13, 2005 at 9:03 AM

Name:   Required
Email:   Required your email address will not be publicly displayed.

Want to receive notifications when new comments are added? Login/Register for an account.

Anti-spam key

Type in the text that you see in the above image:

Your comment:

Sorry, no HTML allowed!