请考虑以下图片:

当我在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>
Run Code Online (Sandbox Code Playgroud)
我收到以下错误:
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
Run Code Online (Sandbox Code Playgroud)
我知道它没有为一些结构定义,如下图所示,但我在<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> ,
Run Code Online (Sandbox Code Playgroud)
您认为if语句中提供了"open",但"Desktop"并不总是可用且未包含在限定语句中.换句话说,"桌面"并不总是一个键,但只要定义了"打开"键,你的循环就会一直查找它.
| 归档时间: |
|
| 查看次数: |
79 次 |
| 最近记录: |