<html>
<head>
<link href="mmres://user_interface_reference.css" rel="stylesheet" type="text/css">
<title>PRESERVESINGLEQUOTES</title>
</head>
<body bgcolor="#FFFFFF" text="#000000">
   <div id="Description">
   <table cellpadding="0" cellspacing="0" border="0" width="100%" class="main">
      <tr> 
         <td valign="top" class="name">PRESERVESINGLEQUOTES</td>
         <td valign="top" nowrap class="compatibility">&nbsp;</td>
      </tr>
      <tr>
         <td colspan="2" class="divider"><img src="dwres:18084" width="100%" height="1"></td>
      </tr>


    </td>
  </tr>
  <tr>
    <td valign="top" colspan="2" class="description"><span class="title">Description</span>
<p>
Prevents ColdFusion from automatically escaping single-quotation mark characters that are contained in a variable. ColdFusion does not evaluate the argument.
</p>
    </td>
  </tr>
  <tr>
    <td valign="top" colspan="2" class="CLEARSEPARATION">&nbsp;</td>
  </tr>
  <tr>
    <td valign="top" colspan="2" class="description"><span class="title">Returns</span>
<p>
(None) 
</p>
    </td>
  </tr>
  <tr>
    <td valign="top" colspan="2" class="CLEARSEPARATION">&nbsp;</td>
  </tr>
  <tr>
    <td valign="top" colspan="2" class="description"><span class="title">Category</span>
<p>
Other functions
</p>
    </td>
  </tr>
  <tr>
    <td valign="top" colspan="2" class="CLEARSEPARATION">&nbsp;</td>
  </tr>
  <tr>
    <td valign="top" colspan="2" class="description"><span class="title">Function syntax</span><pre>PreserveSingleQuotes(variable)
</pre>    </td>
  </tr>
  <tr>
    <td valign="top" colspan="2" class="CLEARSEPARATION">&nbsp;</td>
  </tr>
  <tr>
    <td valign="top" colspan="2" class="description"><span class="title">History</span>
<p>
ColdFusion&#160;MX: Changed behavior: ColdFusion automatically escapes simple-variable, array-variable, and structure-variable references within a cfquery tag body or block. (Earlier releases did not automatically escape array-variable references.)
</p>
    </td>
  </tr>
  <tr>
    <td valign="top" colspan="2" class="CLEARSEPARATION">&nbsp;</td>
  </tr>
  <tr>
    <td valign="top" colspan="2" class="description"><span class="title">Parameters</span>
<p>

</p>
    </td>
  </tr>
  <tr>
    <td valign="top" colspan="2" class="CLEARSEPARATION">&nbsp;</td>
  </tr>
  <tr>
    <td valign="top" colspan="2" class="description"><span class="title">Usage</span>
<p>
This function is useful in SQL statements to defer evaluation of a variable reference until runtime. This prevents errors that result from the evaluation of a single-quote or apostrophe data character (for example, &quot;Joe's Diner&quot;) as a delimiter. 
</p>

<p>
Example A: Consider this code:
</p>
<pre>&lt;cfset mystring = &quot;&#39;Newton&#39;s Law&#39;, &#39;Fermat&#39;s Theorem&#39;&quot;&gt;
PreserveSingleQuotes(#mystring#) is
&lt;cfoutput&gt;
#PreserveSingleQuotes(mystring)#
&lt;/cfoutput&gt; 
</pre>
<p>
The output is as follows:
</p>
<pre>PreserveSingleQuotes(#mystring#) is &#39;Newton&#39;s Law&#39;, &#39;Fermat&#39;s Theorem&#39; 
</pre>
<p>
Example B: Consider this code:
</p>
<pre>&lt;cfset list0 = &quot; &#39;1&#39;,&#39;2&#39;, &#39;3&#39; &quot;&gt;
&lt;cfquery sql = &quot;select * from foo where bar in (#list0#)&quot;&gt;
</pre>
<p>
ColdFusion escapes the single-quote characters in the list as follows:
</p>
<pre>&quot;&quot;1&quot;&quot;, &quot;&quot;2&quot;&quot;, &quot;&quot;3&quot;&quot;
</pre>
<p>
The cfquery tag throws an error.
</p>

<p>
You code this function correctly as follows:
</p>
<pre>&lt;cfquery sql = &quot;select * from foo where bar in 
(#preserveSingleQuotes(list0)#)&quot;&gt; 
</pre>
<p>
This function ensures that ColdFusion evaluates the code as follows:
</p>
<pre>&#39;1&#39;, &#39;2&#39;, &#39;3&#39; 
</pre>    </td>
  </tr>
  <tr>
    <td valign="top" colspan="2" class="CLEARSEPARATION">&nbsp;</td>
  </tr>
  <tr>
    <td valign="top" colspan="2" class="description"><span class="title">Example</span><pre>&lt;h3&gt;PreserveSingleQuotes Example&lt;/h3&gt;&lt;p&gt;This is a useful function for
   creating lists of information to return from a query. In this 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.
&lt;cfset List = &quot;&#39;Suisun&#39;, &#39;San Francisco&#39;, &#39;San Diego&#39;&quot;&gt;
&lt;cfquery name = &quot;GetCenters&quot; datasource = &quot;cfdocexamples&quot;&gt;
   SELECT Name, Address1, Address2, City, Phone
   FROM Centers
   WHERE City IN (#PreserveSingleQuotes(List)#)
&lt;/cfquery&gt;
&lt;p&gt;We found &lt;cfoutput&gt;#GetCenters.RecordCount#&lt;/cfoutput&gt; records.
&lt;cfoutput query = &quot;GetCenters&quot;&gt;
&lt;p&gt;#Name#&lt;br&gt;   
#Address1#&lt;br&gt;
&lt;cfif Address2 is not &quot;&quot;&gt;#Address2#
&lt;/cfif&gt;
#City#&lt;br&gt;
#Phone#&lt;br&gt;
&lt;/cfoutput&gt;
</pre>
         </td>
      </tr>
   </table>
   </div>
<div id="VARIABLE">
<table border="0" cellspacing="0" cellpadding="0" width="100%">
<tr>  
<td valign="top" class="name">VARIABLE</td>
  <td valign="top" nowrap class="compatibility">&nbsp;</td>
  </tr>
  <tr>
  <td colspan="2" class="divider"><img src="dwres:18084" width="100%" height="1"></td>
  </tr>


<p>Variable that contains a string in which to preserve single-quotation marks.</p>

  </td>
  </tr>
  </table>
</div>

  </body>
</html>
