我有一个查询查询,它对变量字符串执行 LIKE 条件:
当变量包含一个包含单引号的单词时,会返回一些结果,但不是全部:
<cfset _myVar = "Women's" />
<cfquery name="_qData" dbtype="Query">
SELECT
ID
FROM MyQoQ
WHERE NAME LIKE '%#_myvar#%'
OR DESCRIPTION LIKE '%#_myvar#%'
</cfquery>
如果变量包含多个单词,并且其中一个单词包含单引号,则不返回任何记录:
<cfset _myVar = "Women's Initiative" />
<cfquery name="_qData" dbtype="Query">
SELECT
ID
FROM MyQoQ
WHERE NAME LIKE '%#_myvar#%'
OR DESCRIPTION LIKE '%#_myvar#%'
</cfquery>
我已经尝试过PreserveSingleQuotes()
用 包装变量CFQUERYPARAM
,但是无济于事 - 我得到了相同的结果。
有没有办法使这项工作?
添加一个复制案例
<cfset myQuery = queryNew('hello')>
<cfset queryAddRow(myQuery,5)>
<cfset querySetCell(myQuery,"hello","what up",1)>
<cfset querySetCell(myQuery,"hello","what's up",2)>
<cfset querySetCell(myQuery,"hello","what's up friends",3)>
<cfset querySetCell(myQuery,"hello","what u",4)>
<cfset querySetCell(myQuery,"hello","what",5)>
<cfdump var="#myQuery#">
<cfquery name="res" dbtype="query">
SELECT *
FROM myQuery
WHERE hello LIKE <cfqueryparam cfsqltype="cf_sql_varchar" value="%$what's up%">
</cfquery>
<cfdump var="#res#">
Railo 4.1.1.009 - 返回两个结果(第 2 行和第 3 行) ColdFusion 10,0,13,287689 - 如果我将 SQL 更改为
WHERE hello LIKE '%what''s up%'
我仍然没有结果