我有一个 .cfm 和 .cfc 用于在 .cfm 上的 cfgrid 中编辑数据,它可以工作,但是 10% 的时间我会收到以下错误消息:
“调用 CFC /test/editCFgrid.cfc 时出错:内部服务器错误”
我尝试使用调试建议,但没有运气。
这是 CFM 代码:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<cfform name="artistform">
<cfgrid format="html" name="artistgrid" pagesize=11
striperows="yes"
bind="cfc:editCFgrid.getArtists({cfgridpage},{cfgridpagesize},{cfgridsortcolumn},{cfgridsortdirection})"
delete="yes" insert="yes" selectmode="edit"
onchange="cfc:editCFgrid.saveArtist({cfgridaction},{cfgridrow},{cfgridchanged})">
<cfgridcolumn name="firstname" header="First Name" />
<cfgridcolumn name="lastname" header="Last Name" />
<cfgridcolumn name="address" header="Address" />
<cfgridcolumn name="city" header="City" />
<cfgridcolumn name="state" header="State" />
<cfgridcolumn name="postalcode" header="Postal Code" />
<cfgridcolumn name="email" header="Email" />
<cfgridcolumn name="phone" header="Phone" />
<cfgridcolumn name="fax" header="Fax" />
<cfgridcolumn name="thepassword" header="Password" />
</cfgrid>
</cfform>
</body>
</html>
这是CFC代码:
<cfcomponent output="FALSE">
<cffunction name="getArtists" hint="I extract artists from the database" access="remote" output="FALSE" returntype="struct">
<cfargument name="page" required="TRUE" hint="the page the grid is on" />
<cfargument name="pagesize" required="TRUE" hint="records displayed per page" />
<cfargument name="gridsortcolumn" required="TRUE" hint="selected column to sort" />
<cfargument name="gridsortdirection" required="TRUE" hint="the sort direction" />
<cfset var qArtists = "" />
<cfif arguments.gridsortcolumn eq "">
<cfset arguments.gridsortcolumn = "lastname" />
<cfset arguments.gridsortdirection = "asc" />
</cfif>
<cfquery name="qArtists" datasource="test_database">
SELECT *
FROM Artists
ORDER BY #arguments.gridsortcolumn# #arguments.gridsortdirection#
</cfquery>
<cfreturn QueryConvertForGrid( qArtists, arguments.page, arguments.pagesize ) />
</cffunction>
<cffunction name="saveArtist" type="any" hint="I insert, update or delete an artist" access="remote" output="FALSE" returntype="void">
<cfargument name="gridaction" type="any" required="TRUE" hint="I for insert, U for update and D for delete" />
<cfargument name="gridrow" type="any" required="TRUE" hint="the rows being inserted or updated" />
<cfargument name="gridchanged" type="any" hint="the changes" />
<cfset var qInsertArtist = "" />
<cfset var qUpdateArtist = "" />
<cfset var qDeleteArtist = "" />
<cfif IsStruct( arguments.gridrow ) and IsStruct( arguments.gridchanged )>
<cfif arguments.gridaction eq "I">
<cfquery name="qInsertArtist" datasource="test_database">
INSERT INTO Artists
(firstname, lastname, address, city, state, postalcode, email, phone, fax, thepassword)
VALUES
(<cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.gridrow.firstname#" />,
<cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.gridrow.lastname#" />,
<cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.gridrow.address#" />,
<cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.gridrow.city#" />,
<cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.gridrow.state#" />,
<cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.gridrow.postalcode#" />,
<cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.gridrow.email#" />,
<cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.gridrow.phone#" />,
<cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.gridrow.fax#" />,
<cfqueryparam cfsqltype="cf_sql_varchar" value="#arguments.gridrow.thepassword#" />)
</cfquery>
<cfelseif arguments.gridaction eq "U">
<cfset var colname = StructKeyList( arguments.gridchanged ) />
<cfset var value = StructFind( arguments.gridchanged, colname ) />
<cfquery name="qUpdateArtist" datasource="test_database">
UPDATE Artists
SET #colname# = <cfqueryparam value="#value#" />
WHERE artistid = <cfqueryparam cfsqltype="cf_sql_integer" value="#arguments.gridrow.artistid#" />
</cfquery>
<cfelseif arguments.gridaction eq "D">
<cfquery name="qDeleteArtist" datasource="test_database">
DELETE FROM Artists
WHERE artistid = <cfqueryparam cfsqltype="cf_sql_integer" value="#arguments.gridrow.artistid#" />
</cfquery>
</cfif>
</cfif>
</cffunction>
</cfcomponent>
每个功能(编辑、插入、删除等)都有效,但它会随机产生错误。最终,我正在寻找一个可以忽略/阻止/“确定”错误消息的代码,这样用户就不会看到它。
任何帮助将不胜感激!我花了一整天(9 个小时)在谷歌上搜索答案,但我没有找到任何答案。我无权访问 CF 管理日志,我只是一个普通的开发人员。谢谢!