cfquery 中的变量作为 SQL

Variable as SQL in cfquery(cfquery 中的变量作为 SQL)
本文介绍了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>

如果我在执行 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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

Execute complex raw SQL query in EF6(在EF6中执行复杂的原始SQL查询)
SSIS: Model design issue causing duplications - can two fact tables be connected?(SSIS:模型设计问题导致重复-两个事实表可以连接吗?)
SQL/MySQL: split a quantity value into multiple rows by date(SQL/MySQL:按日期将数量值拆分为多行)
SQL Server Graph Database - shortest path using multiple edge types(SQL Server图形数据库-使用多种边类型的最短路径)
Invalid column name when using EF Core filtered includes(使用EF核心过滤包括时无效的列名)
How should make faster SQL Server filtering procedure with many parameters(如何让多参数的SQL Server过滤程序更快)