Monday, September 5, 2011

Easy method for setting cfqueryparam null attribute

One function I'm surprised that wasn't built-in to ColdFusion until CF9 is isNull(). Since my company is currently on CF8, I decided to create my own function.  This was useful for me when trying to set the boolean value in cfqueryparam's null attribute.

One solution would be to set a local flag by evaluating len(trim(myvar)), but I thought calling a cfc made more sense, and it is still pretty straightforward.

Feel free to use this code in your non-CF9 applications. I only developed this for use with simple strings, so use with caution. I have now updated the code to handle strings, structs, arrays, and queries. I have not tested nested structures yet. Has anyone used CF9's isNull() function for more complex structures?


  1. Maybe you can do ArrayIsDefined(arguments, 1) instead of try/catch

    1. I still prefer to use try/catch in case the conditionals or anything else fails; that way the user doesn't get a big nasty error message. Plus, I like to add error logging/emailing in the catch for notification.

      In such a trivial function like this, the try/catch is probably unnecessary.

      I've since found a decent way to handle multiple structures. I'll update the post. Stay tuned!