Variable as SQL in cfquery

徘徊边缘 提交于 2019-11-28 12:25:19

问题


I have a table that is storing SQL as one of its elements. I need to be able to run that stored SQL query, but can't figure out how to do it. So far, I'm using the following method:

<cfquery name="qDynamicTag" datasource="#myDSN#">
#PreserveSingleQuotes(arguments.sql)#
</cfquery>

If I dump the value of #PreserveSingleQuotes(arguments.sql)# before executing the cfquery I see the correct SQL statement. However, when I try to run the above cfquery I get a SQLException with the message:

Syntax error at token 0, line 0 offset 0

An example of one of the SQL statements that I'm trying to run:

select productid from catalog.producttag where tag = 'case' or tag = 'cases'

Any ideas on what I'm doing wrong?


回答1:


Ha! Thanks for all your comments. The suggestion to check the debugging output of the DB activity made me realize that I wasn't seeing the DB activity in the debug section of the page because the query was executing through an AJAX call. After calling the page with the query directly, the DB debug output revealed that the code was good, but the data in the database was bad. One of the records with SQL didn't exist. Thus, cfquery was trying to run a blank string.



来源:https://stackoverflow.com/questions/17627795/variable-as-sql-in-cfquery

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!