In general, you only use PreserveSingleQuotes when you want CF to not
automagically escape single quotes.

Normally, if you do this:

INSERT INTO Foo(var)
VALUES('#Form.blah#')

and Form.blah = Ray's World, CF would automatically change it to Ray''s
World (see note at bottom for exception).

However, if you want to do SQL like so, SELECT * FROM FOO WHERE ID IN
('ray','camden','foo') and have VALS="'ray','camden','foo'" and want to
write, WHERE ID IN (#VAL#), you would then need to use PreserveSingleQuotes.
i.e., WHERE ID IN (#PreserveSingleQuotes(VAL)#)

Note: CF will forget to escape single quotes when it encouters a complex
var, like a structure w/ bracket notation. So, if Form.blah was Ray's World,
this would be dangerous:

VALUES('#Form["blah"]#')

I've also seen it have the same problem w/ 2 dimensional arrays. If you are
worried about it, just copy the value to a temp variable.

=======================================================================
Raymond Camden, Principal Spectra Compliance Engineer for Macromedia

Email   : [EMAIL PROTECTED]
ICQ UIN : 3679482

"My ally is the Force, and a powerful ally it is." - Yoda

> -----Original Message-----
> From: Michael Lugassy [mailto:[EMAIL PROTECTED]]
> Sent: Wednesday, May 23, 2001 8:51 AM
> To: CF-Talk
> Subject: The Ugliest Function = PreserveSingleQuotes
>
>
> What's going on with this function? (PreserveSingleQuotes)
> I'm trying to set-up varaiables BEFORE inserting them into SQL table
> like this:
>
> <cfset form.foo1=PreserveSingleQuotes(form.foo1)>
> <cfset form.foo2=PreserveSingleQuotes(form.foo2)>
>
> this doesn't work, but weirdly, this works:
>
> <cfset foo1=PreserveSingleQuotes(foo1)>
> <cfset foo2=PreserveSingleQuotes(foo2)>
>
> I also tried writing that directly into CFQUERY:
>


~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Structure your ColdFusion code with Fusebox. Get the official book at 
http://www.fusionauthority.com/bkinfo.cfm

Archives: http://www.mail-archive.com/[email protected]/
Unsubscribe: http://www.houseoffusion.com/index.cfm?sidebar=lists

Reply via email to