This little bug comes courtesy of my boss at Contens. It appears that the function PreserveSingleQuotes() in Coldfusion 9 is unable to handle the results of a function that returns a string.
The ProblemYou have a simple string, or list and wish to manipulate it, the results of the manipulation is then going to be used in a query so naturally you will want to use PreserveSingleQuotes() to make sure that your single quotes are not removed.
Take the following simple example below:
<cfset mylist = "one,two,three,four">
<cfquery name="getStuff" datasource="#request.dsn#">
select * from mytable
where numbers in (#PreserveSingleQuotes(listQualify(mylist,"'"))#)
Yes I could use cfqueryparam in this case, but for the sake of example lets pretend that I didn't. If you try this code or simply leave out the query and do the following:
ColdFusion 9 will throw an error:
Complex constructs are not supported with function PreserveSingleQuotes. Use simple variable instead.
Pardon me but a string or list is indeed a simple variable! PreserveSingleQuotes will also fail with the following:
<cfoutput>#preserveSingleQuotes(lCase("it's definitely a simple life!"))#</cfoutput>
Work AroundThere is a work around to this ColdFusion 9 bug, simply store the results of the manipulation in a variable and then pass that variable to PreserveSingleQuotes() as I in the following snippet:
<cfset mystring = lCase("it's definitely a simple life!")>
No recent entries.