7

I primarily use CFQUERYPARAM to prevent SQL injection. Since Query-of-Queries (QoQ) does not touch the database, is there any logical reason to use CFQUERYPARAM in them? I know that values that do not match the cfsqltype and maxlength will throw an exception, but, these values should already be validated before that and display friendly messages (from a UX viewpoint).

4

2 回答 2

8

由于 Query-of-Queries (QoQ) 不涉及数据库,是否有任何逻辑理由在其中使用 CFQUERYPARAM?实际上,它确实涉及数据库,即您当前存储在内存中的数据库。该数据库中的数据理论上仍然可以通过用户的某种注入来篡改。这会影响您的物理数据库吗?不。这是否会影响应用程序中数据的使用 - 是的。

您没有提供任何具体细节,但我会谨慎行事。如果您用于构建查询的任何数据都来自客户端,则cfqueryparam在它们中使用。如果您可以保证查询中没有任何元素来自客户端,那么我认为不使用cfqueryparam.

cfqueryparam顺便说一句,虽然我不确定这是否适用于查询查询,但using还有助于优化数据库查询。它还像撇号一样为您转义字符。

于 2014-02-27T16:51:31.833 回答
6

在我看来,这是一种更简单的情况。

<cfquery name="NoVisit" dbtype="query">
select chart_no, patient_name, treatment_date, pr, BillingCompareField
from BillingData
where BillingCompareField not in 
(<cfqueryparam cfsqltype="cf_sql_varchar" 
value="#ValueList(FinalData.FinalCompareField)#" list="yes">)
</cfquery>

另一种方法是使用 QuotedValueList。但是,如果该值列表中的任何内容包含撇号,cfqueryparam 将对其进行转义。否则我将不得不这样做。

编辑从这里开始

这是另一个不使用查询参数导致错误的示例。

QueryAddRow(x,2);
QuerySetCell(x,"dt",CreateDate(2001,1,1),1);
QuerySetCell(x,"dt",CreateDate(2001,1,11),2);
</cfscript>

<cfquery name="y" dbtype="query">
select * from x
<!--- 
where dt in (<cfqueryparam cfsqltype="cf_sql_date" value="#ValueList(x.dt)#" list="yes">) 
--->
where dt in (#ValueList(x.dt)#)
</cfquery>

编写的代码会引发此错误:

Query Of Queries runtime error.  
Comparison exception while executing IN.
Unsupported Type Comparison Exception: 
The IN operator does not support comparison between the following types: 
Left hand side expression type = "DATE".
Right hand side expression type = "LONG".

使用上面注释掉的查询参数,代码成功执行。

于 2014-02-27T16:51:23.497 回答