Coldfuson CFScript“setSQL”没有找到方法
我有一个 Coldfusion 组件,其中有一个名为 getColumnNames 的方法,
这只是查询 MySQL 表,并返回列列表:
remote string function getColumnNames() {
qProcessCars = new Query();
qProcessCars.setDataSource('#APPLICATION.dsn#');
qProcessCars.setSQL('SELECT * FROM sand_cars WHERE 1 LIMIT 1');
qProcessCars = qProcessCars.Execute().getResult();
return qProcessCars.columnlist;
}
如果我在浏览器中使用 page.cfc 远程访问它?method=getColumnNames,然后我得到预期的列列表。
但是,如果我尝试从组件内的另一个方法内部访问它,则会收到错误
remote string function otherFunction() {
...
sColumns = getColumnNames();
...
}
上述代码的错误转储返回消息“未找到 setSQL 方法”。
那么任何人都可以帮助我找出为什么它作为远程调用工作,但在从同一组件内的另一个方法调用时却不起作用。
I've got a Coldfusion component, with a method in it called getColumnNames
This just queries a MySQL table, and returns the columnlist:
remote string function getColumnNames() {
qProcessCars = new Query();
qProcessCars.setDataSource('#APPLICATION.dsn#');
qProcessCars.setSQL('SELECT * FROM sand_cars WHERE 1 LIMIT 1');
qProcessCars = qProcessCars.Execute().getResult();
return qProcessCars.columnlist;
}
If I access this remotely in the browser, with page.cfc?method=getColumnNames, then I get the expected list of columns back.
However, if I try to access this from inside another method within the component, I get an error
remote string function otherFunction() {
...
sColumns = getColumnNames();
...
}
The error dump for the above code returns the message "The setSQL method was not found".
So can anyone help me find out why it works as a remote call, but not when called from another method inside the same component.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
问题可能是由某种竞争条件引起的。如果您很少进行干扰调用,则在某些时候 qProcessCars 可能已经是查询结果,因此无法调用方法。
我会尝试将 qProcessCars 变量设置为局部范围 (var qProcessCars = new Query();
)和/或尝试使用另一个变量名称来获取查询结果。
下一个可能的步骤是将查询构建/执行代码封装到命名锁中。
Problem may be caused some kind of race conditions. If you make few calls which interfere, at some point qProcessCars may already be query result, so invoking method is not possible.
I would try to make the
qProcessCars
variable local scoped (var qProcessCars = new Query();
) and/or try to use another variable name for query results.Next possible step is to enclose the query building/executing code into named lock.
啊我又回答了我自己的问题。对不起。
我在组件中的其他位置使用了相同的名称 qProcessCars,但我没有将 var 放在它们前面。
我不知道为什么这会导致问题,但确实如此。也许每个查询对象只能调用setSQL一次?
Ah I've answered my own question again. Sorry.
I've used the same name qProcessCars else where in the component, I hadn't put var in front of them.
I don't know WHY that was causing the problem, but it was. Maybe setSQL can only be called once per query object?