假设有一个 SQL 表Fruit
id | name
--- ------
1 | 'apples'
2 | 'pears'
3 | 'kiwi'
4 | 'bananas, peaches and plumbs'
鉴于以下查询
<cfquery name="qAllFruit" datasource="#DSN#">
SELECT name FROM Fruit
</cfquery>
<cfquery name="qLeftoverFruit" datasource="#DSN#">
SELECT name FROM Fruit
WHERE name NOT IN (<cfqueryparam CF_SQL_TYPE="CF_SQL_VARCHAR"
value="#ValueList(qAllFruit.name)#"
list="yes" />)
</cfquery>
thenqLeftoverFruit
将错误地返回 1 行:bananas, peaches and plumbs
因为扩展cfqueryparam
列表的解释不正确:
WHERE name NOT IN ('apples','pears','kiwi','bananas','peaches and plumbs')
有没有办法在仍然使用cfqueryparam
标签的同时纠正这个问题ValueList
?
更新这里有一个要点可以用来重新创建这个问题: http: //gist.github.com/a642878c96b82b21b52c