变量为cfquery中的SQL [英] Variable as SQL in cfquery

查看:238
本文介绍了变量为cfquery中的SQL的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个表存储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>



如果我转储的值 #PreserveSingleQuotes(arguments.sql)#在执行cfquery之前我看到正确的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'

推荐答案

哈!感谢您的所有意见。检查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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆