问题描述
我有一个将 SQL 存储为其元素之一的表.我需要能够运行存储的 SQL 查询,但不知道该怎么做.到目前为止,我使用的是以下方法:
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>
如果我在执行 cfquery 之前转储 #PreserveSingleQuotes(arguments.sql)#
的值,我会看到正确的 SQL 语句.但是,当我尝试运行上述 cfquery 时,我会收到一条带有以下消息的 SQLException:
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
我尝试运行的 SQL 语句之一的示例:
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?
推荐答案
哈!谢谢你们的评论.检查 DB 活动的调试输出的建议使我意识到我没有在页面的调试部分看到 DB 活动,因为查询是通过 AJAX 调用执行的.直接用查询调用页面后,DB调试输出显示代码是好的,但是数据库中的数据是坏的.SQL 记录之一不存在.因此,cfquery 试图运行一个空白字符串.
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.
这篇关于cfquery 中的变量作为 SQL的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!