[英]Error Executing database query
What am I doing wrong here: 我在这里做错了什么:
<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>
You can refer to my previous post for more information: inserting structure elements into database 您可以参考我以前的文章以获取更多信息: 将结构元素插入数据库
SQL Fiddle for Table Structure: http://sqlfiddle.com/#!2/e255c/1 表结构的SQL Fiddle: http ://sqlfiddle.com/#!2 / e255c / 1
Where date, start and end date are datetime in my database table. 日期,开始日期和结束日期是数据库表中的日期时间。
Error Message: 错误信息:
Error Executing Database Query. 执行数据库查询时出错。 You have an error in your SQL syntax;
您的SQL语法有误; check the manual that corresponds to your MySQL server version for the right syntax to use near '5 5 5 '2014-01-06' 10 ) ( '2014-01-07' 3 ' at line 8
检查与您的MySQL服务器版本相对应的手册以获取正确的语法,以在第8行的'5 5 5'2014-01-06'10)('2014-01-07'3'
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")>
You don't have commas after each element / column in your query. 查询中的每个元素/列后都没有逗号。
Your error shows it: 您的错误显示了它:
'5 5 5 '2014-01-06' 10 ) '5 5 5'2014-01-06'10)
Add commas 添加逗号
'5, 5, 5, '2014-01-06', 10 ) '5,5,5,'2014-01-06',10)
That's the key issue. 那是关键问题。
You need to put a comma between each value in the bracketed values section of your SQL statement. 您需要在SQL语句的带括号的值部分中的每个值之间添加逗号。
The comma goes after each if statement so the result would be : 逗号在每个if语句之后,因此结果为:
VALUES (NULL,NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL, NULL) 值(NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL,NULL)
if you had none of your struct keys. 如果您没有任何结构键。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.