我的递归方法调用有什么问题?
我有一个执行存储过程并返回结果的搜索函数。如果没有结果,我想尝试通过更广义的搜索再次运行该函数。因此,我将 cfif 放入我的代码中 -
<cfif results.recordCount EQ 0 And Not arguments.searchForPotentialMatches>
<cfset arguments.searchForPotentialMatches = True />
<cfinvoke method="thisMethod" argumentCollection="#arguments#" />
</cfif>
基本上,如果没有结果并且我还没有尝试通用搜索,它应该再次调用此方法。然后,在方法的开头,在调用存储过程之前,我检查 searchForPotentialMatches 是否为 true,如果是,则概括搜索查询。
不过,似乎有一个问题...当我尝试运行它时,它会挂起 - 直到存储过程超时。通过调试和输出变量,我已经能够看到它到达存储过程,然后在尝试执行它时陷入困境。但是,在这些重新运行更改之前使用原始函数,如果我进行常规搜索,然后在 2 个单独的调用中进行广义搜索,它会正确执行。所以我不确定为什么当我尝试以编程方式构建它时它会失败......我做错了什么?
I have a search function that executes a stored procedure and returns results. If there are no results, I want to try running the function one more time with a more generalized search. So, I put a cfif into my code -
<cfif results.recordCount EQ 0 And Not arguments.searchForPotentialMatches>
<cfset arguments.searchForPotentialMatches = True />
<cfinvoke method="thisMethod" argumentCollection="#arguments#" />
</cfif>
Basically, if there were no results AND I haven't already tried a generalized search, it should invoke this method again. Then, in the beginning of the method, before calling the stored procedure, I check if searchForPotentialMatches is true, and if it is, I generalize the search query.
There seems to be a problem, though... When I try to run this, it hangs - until there's a timeout with the stored procedure. Through debugging and outputting variables, I've been able to see that it gets to the stored procedure, and then gets stuck trying to execute it. However, using the original function before these rerun changes, if I do the regular search and then the generalized search in 2 separate calls, it executes correctly. So I'm not sure why it fails when I try to build this in programmatically... What am I doing wrong?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
函数标签上的访问属性是什么,您是否给它一个使函数无法调用自身的值?
What is your access attribute on the function tag, have you given it a value that leaves the function unable to call itself?
这感觉不公平......但问题是完全不同的东西。递归调用工作正常,但由于在调用存储过程之前检查函数并导致存储过程挂起,因此另一个字段发生了更改。对此深表歉意,并感谢您的帮助!
This feels unfair... But the issue was with something completely different. The recursive call works correctly, but there was another field that was getting changed due to a check in the function before calling the stored procedure and causing the stored proc to hang. Sorry about that, and thanks for all your help!
确实可以有很多东西。所有这些代码都在 cfc 中吗? cfc 是否处于持久作用域中,并且您是否正确地对所有变量进行了 var'd 操作?
您能否在正常和通用条件下独立执行存储过程而不会出现问题?
尝试粘贴更多代码(包括对存储过程的第一次调用),以便我们可以尝试更多地跟踪您的数据流。
Could really be any number of things. Is all of this code inside of a cfc? Is that cfc in a persistent scope and have you properly var'd all your variables?
Can you execute the stored proc under both normal and generalized conditions standalone without issue?
Try pasting in more of your code (including the first call to the stored proc) so we can try to trace your data flow a bit more.
递归是:
所以正如你所写,我会失去递归,并按顺序进行。由于没有@scrittler 要求的更多代码,我将重写如下:
Recursion is:
So as you wrote, I'd lose the recursion, and do it sequentially. Absent any more code as @scrittler requested, I'd rewrite as such: