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?