我正在尝试保护此代码,但每次添加 cfqueryparam 标记时,我都会收到有关参数绑定的错误。我确定我将cfsqltype
属性设置为正确的值。最后一个 select 语句是所有地狱都崩溃的地方。
<CFQUERY name="getLatestSurveyID" datasource="#REQUEST.dsn#">
SELECT TOP 1
SurveyID
FROM
TUser_WelcomeHome
ORDER BY
SurveyID DESC
</CFQUERY>
<!--- Throw the Reasons/Subreasons into the DB --->
<!---adding cfqueryparam tags breaks following CFIF block--->
<CFIF ListLen(SESSION.WHSurveyStruct.reasonString, ";") gt 0>
<CFQUERY name="insertReasons" datasource="#REQUEST.dsn#">
INSERT INTO TWelcomeHome_Reason
(ReasonID, SubReasonID, SurveyID)
SELECT #sanitize(ListFirst(SESSION.WHSurveyStruct.reasonString, ";"))#, #sanitize(getLatestSurveyID.SurveyID)# <!---error occures if adding cfqueryparam tags on this line--->
<CFLOOP list="#sanitize(ListRest(SESSION.WHSurveyStruct.reasonString, ';'))#" index="thisReason" delimiters=";">
UNION ALL
SELECT #sanitize(thisReason)#, #sanitize(getLatestSurveyID.SurveyID)#
</CFLOOP>
</CFQUERY>
上面的代码有效,但如果我做了以下更改,它将不起作用:
<cfqueryparam value=#sanitize(getLatestSurveyID.SurveyID)# cfsqltype="cf_sql_integer">
这是参数化导致的错误
<cfqueryparam value=#sanitize(getLatestSurveyID.SurveyID)# cfsqltype="cf_sql_integer">
执行数据库查询时出错。[Macromedia][SQLServer JDBC 驱动程序][SQLServer]INSERT 语句与 FOREIGN KEY 约束“FK_WelcomeHome_TSupplier”冲突。冲突发生在数据库“d21wca1”、表“dbo.TSupplier”、列“SupplierID”中。错误发生在 D:/Resource/www/dev/ww1test.owktravel.com/welcome_survey/welcome_survey_router.cfm: line 215 Called from D:/Resource/www/dev/ww1test.owktravel.com/welcome_survey/welcome_survey_router.cfm:第 183 行从 D:/Resource/www/dev/ww1test.owktravel.com/welcome_survey/welcome_survey_router.cfm 调用:第 174 行从 D:/Resource/www/dev/ww1test.owktravel.com/welcome_survey/welcome_survey_router.cfm 调用:第 1 行从 D:/Resource/www/dev/ww1test.owktravel.com/welcome_survey/welcome_survey_router.cfm 调用:
编辑:我仍然无法理解循环在做什么。SELECT
语句不是丢失了FROM
吗?