Back to the notebook

PreserveSingleQuote Gotcha

After scratching my head for a while wondering why the below code;<cfquery datasource="myDSN" name="qry">#preservesinglequotes(myArray[1])#</cfquery>was returning the error. Invalid CFML construct found on line 8 at column 26.
ColdFusion was looking at the following text:
[
I was sure that the array held a query then have just found out that preserveSingleQuotes only excepts simple values. So the above code should look more like<cfset sqlQry = myArray[1] /><cfquery datasource="myDSN" name="qry">#preservesinglequotes(sqlQry)#</cfquery>You would think that surely this could be error trapped by the CF server to inform you that you can only pass in simple values?

Leave a note.