【发布时间】:2014-03-17 11:28:57
【问题描述】:
请考虑以下图片:
当我在 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> ,
【问题讨论】:
-
我不知道如何在coldfusion中做到这一点,但你应该打印出正在生成的最终查询,让我们看看。
-
Damien,在生成 SQL 之前就出错了。这是 ColdFusion 错误,而不是 SQL 错误。
-
我之前已经讨论过与此类查询相关的问题:stackoverflow.com/questions/21470019/… 谢谢!
标签: mysql coldfusion