Chris Luksha (Echowebs) wrote:
> So why would it work directly in the select statement -
but not if you
> PRE qualified it?
> Anyone wanna venture a guess?
CF automatically escapes (ie doubles) single quotes found
inside query variables as a security mechanism. So if you pass in a
value containing single quotes, they will be doubled. In your first
example URL.background
does contain single quotes.
<cfset URL.Background =
ListQualify(URL.Background,"'",",","CHAR")>
ie. URL.background = 'black', 'blue', 'red'
In your second example URL.Background does
not contain single quotes.
URL.Background = black, blue, red.
Which explains why one works and the other does not. However,
a simpler method is to just use cfqueryparam with the "list"
attribute. Notice how you do not have to worry about quoting list
values? CF automatically handles that for you.
<cfset URL.background = "black,blue,red">
...
WHERE ColumnName IN (
<cfqueryparam value="#url.background#" list="true"
cfsqltype="cf_sql_varchar">
)
SELECT ID FROM table WHERE style IN(#URL.style#) When
url.style=1,2,3,4
That may expose your database to sql injection risks.
Consider using cfqueryparam with all of your query parameters.