Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

sql building, apostrophe escaping, behavior diff from CF6.1 & CF8

Status
Not open for further replies.

dakota81

Technical User
May 15, 2001
1,691
US
Quick Example:
<cfquery datasource="..." name="...">
SELECT * FROM table WHERE field1='#variable#'
</cfquery>

Let's say variable = "foo'bar"

In CF6.1 and CF8, the query passed to the database is:
SELECT * FROM table WHERE field1='foo''bar'


If variable = "foo''bar"

In CF6.1, the query passed to the database is:
SELECT * FROM table WHERE field1='foo''''bar'

In CF8, the query is:
SELECT * FROM table WHERE field1='foo''bar'



If I can, I would prefer ColdFusion 8 to mimic the behavior of ColdFusion 6.1 so I don't have to go back and check all my past work now that my server has been upgraded. Is this even possible? Thanks.
 
To add, I know I can update the script to be:
<cfquery datasource="..." name="...">
SELECT * FROM table WHERE field1='#Replace(variable,"''","''''","ALL")#'
</cfquery>

But I'd hope I wouldn't have to on each query.
 
What about using: cfqueryparam?
Code:
select * 
from table 
where field1 = <cfqueryparam cfsqltype="cf_sql_varchar" value="#var#">

I don't think you'll need to worry about apostrophes or double quotes in the variable then.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top