SQL Query breaking for some reason

二次信任 提交于 2019-12-24 14:13:51

问题


Please consider the following Image:

When I ran the following query in 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>

I get the following error:

 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

I know it's not defined for some of the structures as shown in the image below, but I have included "NULL" in my <cfelse> statement to handle those cases. Am I doing something wrong here? Please advise.

However the query runs fine for the date range where OPEN'S are defined.

Correct Way:

<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> ,

回答1:


You qualify that "open" is available in your if statement, but "Desktop" is not always available and is not wrapped in a qualifying statement. If other words, "Desktop" is not always a key, but your loop always looks for it as long as the "open" key is defined.



来源:https://stackoverflow.com/questions/21841437/sql-query-breaking-for-some-reason

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!