(From the "Things that make you go 'Grrrrr'" file...)

This is an extremely rhetorical question, but what is up with the stupid
in-query single quote escaping?  Sometimes it works, sometimes it doesn't.
I think I've tracked it down to a simple rule: if your variable has brackets
[] in it, it isn't escaped, but otherwise it is.  So, if you are going to
access the data using an array (or a structure with brackets) you need to
escape the single quotes *before* you use them in the query.  Other wise,
don't escape them or they'll just be escaped again.

How exceedingly lame.  One or the other.  Make up your mind.

Code used to test and results follow.

Results:

Strings work.
Arrays are broke.
Structs with dots work.
Structs with brackets are broke.

Code:

<CFSET string="qu'ux">
<CFSET array=ArrayNew(1)>
<CFSET array[1]="qu'ux">
<CFSET struct=StructNew()>
<CFSET struct.name="qu'ux">
<CFTRY>
  <CFQUERY DATASOURCE="#Application.DataSource#" NAME="foo">
  SELECT *
  FROM bugs_bugs
  WHERE (area_tx = '#string#')
  </CFQUERY>
  <CFOUTPUT><P>Strings work.</P></CFOUTPUT>
<CFCATCH><CFOUTPUT><P>Strings are broke.</P></CFOUTPUT></CFCATCH>
</CFTRY>
<CFTRY>
  <CFQUERY DATASOURCE="#Application.DataSource#" NAME="foo">
  SELECT *
  FROM bugs_bugs
  WHERE (area_tx = '#array[1]#')
  </CFQUERY>
  <CFOUTPUT><P>Arrays work.</P></CFOUTPUT>
<CFCATCH><CFOUTPUT><P>Arrays are broke.</P></CFOUTPUT></CFCATCH>
</CFTRY>
<CFTRY>
  <CFQUERY DATASOURCE="#Application.DataSource#" NAME="foo">
  SELECT *
  FROM bugs_bugs
  WHERE (area_tx = '#struct.name#')
  </CFQUERY>
  <CFOUTPUT><P>Structs with dots work.</P></CFOUTPUT>
<CFCATCH><CFOUTPUT><P>Structs with dots are broke.</P></CFOUTPUT></CFCATCH>
</CFTRY>
<CFTRY>
  <CFQUERY DATASOURCE="#Application.DataSource#" NAME="foo">
  SELECT *
  FROM bugs_bugs
  WHERE (area_tx = '#struct["name"]#')
  </CFQUERY>
  <CFOUTPUT><P>Structs with brackets work.</P></CFOUTPUT>
<CFCATCH><CFOUTPUT><P>Structs with brackets are
broke.</P></CFOUTPUT></CFCATCH>
</CFTRY>


--
Rick Osborne

------------------------------------------------------------------------------
Archives: http://www.mail-archive.com/[email protected]/
To Unsubscribe visit 
http://www.houseoffusion.com/index.cfm?sidebar=lists&body=lists/cf_talk or send a 
message to [EMAIL PROTECTED] with 'unsubscribe' in the body.

Reply via email to