PreserveSingleQuotes

Description

Prevents ColdFusion from automatically "escaping" single quotes contained in variable.

Category

Other functions

Syntax

PreserveSingleQuotes(variable) 

Parameters

Parameter
Description
variable
Variable that contains a string for which single quotes are preserved.

Usage

PreserveSingleQuotes is useful in SQL statements.

Example

<!--- This example shows the use of PreserveSingleQuotes --->
<html>
<head>
<title> PreserveSingleQuotes Example </title>
</head>

<basefont face = "Arial, Helvetica" size = 2>
<body bgcolor = "#FFFFD5">

<H3>PreserveSingleQuotes Example</H3>
<P>This is a useful function for creating lists of information to 
return from a query. In the following example, we pick the list 
of Centers in Suisun, San Francisco, and San Diego, using the SQL
grammar IN to modify a WHERE clause rather than looping through 
the result set after the query is run.

<cfset List = "'Suisun', 'San Francisco', 'San Diego'">

<cfquery name = "GetCenters" datasource = "cfsnippets">
  SELECT Name, Address1, Address2, City, Phone
  FROM Centers
  WHERE City IN (#PreserveSingleQuotes(List)#)
</cfquery>

<P>We found <cfoutput>#GetCenters.RecordCount#</cfoutput> records.
<cfoutput query = "GetCenters">
<P>#Name#<BR>  
#Address1#<BR>
<cfif Address2 is not "">#Address2#</cfif>
#City#<BR>
#Phone#<BR>
</cfoutput>
</body>
</html>