请考虑以下图片:
当我在coldfusion中运行以下查询时:
<cfquery datasource="mydb" name="qCoulmnInsert">
INSERT INTO
simplexresults.contactresults_email_account_summary_devices
(open_desktop_int,
open_other_int,
open_phone_int,
open_tablet_int,
open_webmail_int,
<!--- FOR Unique Open --->
unique_webMail_int,
unique_tablet_int,
unique_other_int,
unique_phone_int,
unique_desktop_int,
<!--- FOR DATES --->
startdate_dt,
enddate_dt,
date_dt)
VALUES
<!--- loop through your array --->
<cfloop from="1" to="#arrayLen(cfData)#" index="i">
(
<cfif structKeyExists(cfData[i], "open")>
<cfqueryparam CFSQLTYPE="CF_SQL_INTEGER" value="#cfData[i].open.Desktop#">
<cfelse>
NULL
</cfif> ,
<cfif structKeyExists(cfData[i], "open")>
<cfqueryparam CFSQLTYPE="CF_SQL_INTEGER" value="#cfData[i].open.Other#">
<cfelse>
NULL
</cfif> ,
<cfif structKeyExists(cfData[i], "open")>
<cfqueryparam CFSQLTYPE="CF_SQL_INTEGER" value="#cfData[i].open.Phone#">
<cfelse>
NULL
</cfif> ,
and so on and so forth ...
....
</cfquery>
我收到以下错误:
Element OPEN.DESKTOP is undefined in a CFML structure referenced as part of an expression.
The error occurred in C:\myfile.cfm: line 55
53 : (
54 : <cfif structKeyExists(cfData[i], "open")>
55 : <cfqueryparam CFSQLTYPE="CF_SQL_INTEGER" value="#cfData[i].open.Desktop#">
56 : <cfelse>
57 : NULL
我知道它没有为某些结构定义,如下图所示,但我在<cfelse>
语句中包含了“NULL”来处理这些情况。我在这里做错了吗?请指教。
但是,对于定义OPEN'S的日期范围,查询运行正常。
正确方式:
<cfif structKeyExists(cfData[i], "open")>
<cfif structKeyExists(cfData[i].open,"Desktop")>
<cfqueryparam CFSQLTYPE="CF_SQL_INTEGER" value="#cfData[i]["open"]["Desktop"]#">
<cfelse>
NULL
</cfif>
<cfelse>
NULL
</cfif> ,
答案 0 :(得分:7)
您认为if语句中提供了“open”,但“Desktop”并不总是可用且未包含在限定语句中。如果换句话说,“桌面”并不总是一个键,但只要定义了“打开”键,你的循环就会一直寻找它。