使用带有 cfscript 查询的查询参数时出错 [英] Error using Query Parameters with cfscript query
问题描述
这是我的代码:
var qryStr = "
UPDATE templates_email
SET title = :title, test_emails = :testEmail, body = :body
WHERE id = :templateID";
q = New Query();
q.setSQL(qryStr);
q.addParam(name="title", value="#arguments.title#", cfsqltype="cf_sql_char");
q.addParam(name="body", value="#arguments.templateContent#", cfsqltype="cf_sql_char");
q.addParam(name="testEmail", value="#arguments.test_emails#", cfsqltype="cf_sql_char");
q.addParam(name="templateID", value="#arguments.id#", cfsqltype="cf_sql_integer");
return q.execute().getResult();
这是错误:
在指定的参数列表中找不到参数body WHERE"
Parameter 'body WHERE' not found in the list of parameters specified
SQL: UPDATE templates_email SET title = :title, test_emails = :testEmail, body = :body WHERE id = :templateID
SQL: UPDATE templates_email SET title = :title, test_emails = :testEmail, body = :body WHERE id = :templateID
错误发生在 C:ColdFusion9CustomTagscomadobecoldfusionquery.cfc: line 108
The error occurred in C:ColdFusion9CustomTagscomadobecoldfusionquery.cfc: line 108
我只能假设我在使用参数构造 SQL 的方式上做错了,但无法弄清楚它是什么.谁能看到我在这里做错了什么?
I can only assume I have done something wrong with the way my SQL is structured with the parameters, but can't work out what it is. Can anyone see what I am doing wrong here?
推荐答案
获取参数的解析器不会对返回值进行标记,只对空格进行标记(这真的很烦人).请尝试以下操作:
The parser for getting the params doesn't tokenize on return values, only on whitespace (which is really annoying). Try the following:
var qryStr = "
UPDATE templates_email
SET title = ( :title ), test_emails = ( :testEmail ), body = ( :body )
WHERE ( id = :templateID )
";
(
和 )
应该消除解析器无法识别 :params 停止和启动位置的任何问题.
The (
and )
should remove any issue with where the parser not being able to recognise where the :params stop and start.
这篇关于使用带有 cfscript 查询的查询参数时出错的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!