ColdFusion Thinks My List Is A Date
coldfusionI came across something interesting today when build a query for testing. I did the following:
<cfscript>
q = queryNew("id,name,list");
queryAddRow(q, 3);
querySetCell(q, "id", 1, 1);
querySetCell(q, "name", "robert", 1);
querySetCell(q, "list", "1,2,3", 1);
querySetCell(q, "id", 2, 2);
querySetCell(q, "name", "ryan", 2);
querySetCell(q, "list", "1,3", 2);
querySetCell(q, "id", 3, 3);
querySetCell(q, "name", "greg", 3);
querySetCell(q, "list", "3,4", 3);
</cfscript>Out of habit, I dumped the "q" to verify that I have what I want. When doing this, what do you think I got?
I thought I'd get an INTEGER (id) and 2 VARCHARs (name & list). Is that what you thought? Well, that's not the case. QuerySetCell determined that the "list" column values represent dates. This is what it gave me.

When I used 2 or 3 numbers in the list, that fell within some sort of date value range, ColdFusion set it's datatype to DATE. If I add rows that only have 1 list value, more than 3 list values, or list values that seem to break the DATE mold (e.g. "40,40"), then I'd get the VARCHAR list that I wanted.
So what is the lesson learned here? ALWAYS define your datatypes when using QueryNew.
Have you come across any other functions that produce unexpected results?




Loading....