the importance of the de function

Today I was adding some functionality to a file upload tool. It rips through a comma separated file provided by clients and then based on what is in that file, inserts data into the database.

Because of some legacy database column types and some flexibility that is needed, we could possibly put a date in a varchar field. This date must be formatted correctly, or the string to string comparison will not work.

Here is the code I was using to check for a date within a cfprocparam tag:

<cfprocparam cfsqltype="CF_SQL_VARCHAR" type="in" value="#iif(isDate(arguments.uploadFile.getField2(),dateFormat(arguments.uploadFile.getField2(),"mm/dd/yyyy"),arguments.uploadFile.getField2())#">

So, what it did, was instead of taking the value I wanted in there, it evaluated it out and it did the math of (1/1/1965) and put a huge decimal into the database. I couldn't figure it out until one of my coworkers said, you forgot the de() function! If you don't add the de() function in there you get some weird results. If you have a dynamic ColdFusion variable you want to use in an iif() you need the de() function. My solution was this:

<cfprocparam cfsqltype="CF_SQL_VARCHAR" type="in" value="#iif(isDate(arguments.uploadFile.getField2(),de(dateFormat(arguments.uploadFile.getField2(),"mm/dd/yyyy")),de(arguments.uploadFile.getField2()))#">

coldfusion tip of the day

I am trying to blog more often. So, to help with that I am going to try to start doing a "Tip of the Day", even though it might not be every day. See, I am already trying to get out of it.

I was looking at some code today, and could not figure out why something was not displaying. Here is the if statement I was looking at:

<cfif isQuery("variables.myQuery")>
Show something here.
</cfif>

Do you see it? I didn't at first either. ColdFusion is treating variables.myQuery as a string. The solution I used was to remove the quotes, and everything worked. You could also put pound signs around variables.myQuery inside the quotes.

BlogCFC was created by Raymond Camden. This blog is running version 5.7.002.