ColdFusion’s documentation for the valuelist function says that it does NOT evaluate the values, and that’s how it’s always behaved for me in the past. I’ve used the valuelist function many times in the past and have never encountered this issue before. We’re using CF9.0.1 but this originally popped up on an instance of CF9.0.
The situation came up as we pull number values from an Oracle database, which DOES support float values. The values stored are all integers, not floats. The code below replicates the behavior we’re seeing. The data is retrieved via stored procedures which we CAN change (using CAST), but would like to avoid if possible.
<cfscript>
qryVLTest = queryNew('member_id') ;
for ( i = 1; i LTE 10; i=i+1) {
queryAddRow(qryVLTest,1) ;
querySetCell(qryVLTest,'member_id',i) ;
}
writedump(qryVLTest) ;
writeoutput(valuelist(qryVLTest.member_id)) ;
</cfscript>
The dump displays the values I expect: integers 1-10.
However, the output of the valuelist function is returning the following:
1,2.0,3.0,4.0,5.0,6.0,7.0,8.0,9.0,10.0
All values after the first one are being evaluated and converted into floats. Why is this, and how can I prevent this in the future?
You have 2 choices. You could do:
Which should force a string. Or you can specify INT if that is what you want (as azawaza has indicated).