Skip to main content
Inspiring
June 24, 2008
Question

preservesinglequotes not working ?

  • June 24, 2008
  • 2 replies
  • 769 views
I work with CF MX V7,

I use this code, and the SQL update failed : (with a single quote in the text)
<cfset des=" test test ' test ">

<cfquery name="insert_prod" datasource="#boutique_datasource#">
update produits_lang
set description='#preservesinglequotes(des)#'
where id_prod=#form.id_prod# and prod_lang_code='#lang_code#'
</cfquery>

Error message : missing operator etc....
It does not allow the single quote in the text !

Help, thanks for any solution ?
Pierre.
This topic has been closed for replies.

2 replies

Inspiring
June 24, 2008
plarts wrote:
> I work with CF MX V7,
>
> I use this code, and the SQL update failed : (with a single quote in the text)
> <cfset des=" test test ' test ">

preservesinglequotes does the opposite of what you want for a db insert:

"Prevents ColdFusion from automatically escaping single-quotation mark
characters that are contained in a variable."

you *want* cf to escape the single quote in this case.

Inspiring
June 24, 2008
Use <cfqueryparam> and you don't need to use preserveSingleQuotes() for
that sort of thing anyhow.

--
Adam