我在这里做错了什么:
<cfquery datasource="mydb" name="qCoulmnInsert">
INSERT INTO
mytable (delivered_int,unique_open_int,spamreport_int,drop_int,request_int,bounce_int,deferred_int, processed_int,date_dt,startdate_dt,enddate_dt,open_int,blocked_int)
VALUES
<!--- loop through your array --->
<cfloop from="1" to="#arrayLen(cfData)#" index="i">
(
<cfif structKeyExists(cfData[i], "delivered")>
<cfqueryparam CFSQLTYPE="CF_SQL_INTEGER" value="#cfData[i].delivered#">
<cfelse>
NULL
</cfif>
<cfif structKeyExists(cfData[i], "unique_open")>
<cfqueryparam CFSQLTYPE="CF_SQL_INTEGER" value="#cfData[i].unique_open#">
<cfelse>
NULL
</cfif>
<cfif structKeyExists(cfData[i], "spamreport")>
<cfqueryparam CFSQLTYPE="CF_SQL_INTEGER" value="#cfData[i].unique_open#">
<cfelse>
NULL
</cfif>
<cfif structKeyExists(cfData[i], "drop")>
<cfqueryparam CFSQLTYPE="CF_SQL_INTEGER" value="#cfData[i].drop#">
<cfelse>
NULL
</cfif>
<cfif structKeyExists(cfData[i], "request")>
<cfqueryparam CFSQLTYPE="CF_SQL_INTEGER" value="#cfData[i].request#">
<cfelse>
NULL
</cfif>
<cfif structKeyExists(cfData[i], "bounce")>
<cfqueryparam CFSQLTYPE="CF_SQL_INTEGER" value="#cfData[i].bounce#">
<cfelse>
NULL
</cfif>
<cfif structKeyExists(cfData[i], "deferred")>
<cfqueryparam CFSQLTYPE="CF_SQL_INTEGER" value="#cfData[i].deferred#">
<cfelse>
NULL
</cfif>
<cfif structKeyExists(cfData[i], "processed")>
<cfqueryparam CFSQLTYPE="CF_SQL_INTEGER" value="#cfData[i].processed#">
<cfelse>
NULL
</cfif>
<cfif structKeyExists(cfData[i], "date")>
<cfqueryparam CFSQLTYPE="CF_SQL_DATE" value="#cfData[i].date#">
<cfelse>
NULL
</cfif>
<cfif structKeyExists(cfData[i], "startdate_dt")>
<cfqueryparam CFSQLTYPE="CF_SQL_DATE" value="#cfData[i].startdate_dt#">
<cfelse>
NULL
</cfif>
<cfif structKeyExists(cfData[i], "enddate_dt")>
<cfqueryparam CFSQLTYPE="CF_SQL_DATE" value="#cfData[i].enddate_dt#">
<cfelse>
NULL
</cfif>
<cfif structKeyExists(cfData[i], "open")>
<cfqueryparam CFSQLTYPE="CF_SQL_INTEGER" value="#cfData[i].open#">
<cfelse>
NULL
</cfif>
<cfif structKeyExists(cfData[i], "blocked")>
<cfqueryparam CFSQLTYPE="CF_SQL_INTEGER" value="#cfData[i].blocked#">
<cfelse>
NULL
</cfif>
)
<cfif i neq arrayLen(cfData)>,</cfif>
</cfloop>
</cfquery>
您可以参考我以前的帖子获取更多信息:inserting structure elements into database
表结构的SQL小提琴:http://sqlfiddle.com/#!2/e255c/1
日期,开始和结束日期是我的数据库表中的日期时间。
错误消息:
执行数据库查询时出错。 您的SQL语法有错误;查看与您的MySQL服务器版本对应的手册,以便在'5 5 5'2014-01-06'10)附近使用正确的语法('2014-01-07'3'在第8行
The error occurred in C:\myfile.cfm: line 55
Called from C:\application.cfc: line 386
Called from C:\myfile.cfm: line 55
Called from C:\application.cfc: line 386
53 : VALUES
54 : <!--- loop through your array --->
55 : <cfloop from="1" to="#arrayLen(cfData)#" index="i">
56 : (
57 : <cfif structKeyExists(cfData[i], "delivered")>
答案 0 :(得分:2)
查询中的每个元素/列后面都没有逗号。
您的错误显示:
'5 5 5'2014-01-06'10)
添加逗号
'5,5,5,'2014-01-06',10)
这是关键问题。
答案 1 :(得分:2)
您需要在SQL语句的括号值部分中的每个值之间添加逗号。
逗号在每个if语句之后,因此结果将是:
VALUES(NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL)
如果你没有任何结构键。