复杂更新语句的 cfquery 问题
我正在尝试使用 cfquery 触发更新查询,如下所示
<cfquery name = "UpdateRecord"
dataSource = #DATASOURCE#
username = #DBUSER#
password = #DBPASSWORD#
result="updateResult" >
update table1
set field1=( select field1 from table2 where field3='Some Value')
where field4='someothervalue'
</cfquery>
<cfdump var="#UpdateResult#">
但是,当我执行此页面时,该页面未加载,在状态栏中我可以看到它加载了很长时间。
但是,如果我使用任何简单的更新查询,那么
update table1 set field1='abc' where field4='someothervalue'
它工作正常
任何人都可以知道如何使用 cfquery 执行上面这样的查询吗?
谢谢
I am trying to fire Update Query using cfquery like below
<cfquery name = "UpdateRecord"
dataSource = #DATASOURCE#
username = #DBUSER#
password = #DBPASSWORD#
result="updateResult" >
update table1
set field1=( select field1 from table2 where field3='Some Value')
where field4='someothervalue'
</cfquery>
<cfdump var="#UpdateResult#">
But, when I execute this page, the page is not loading, in status bar I can see its loading for long time.
But If I use any simple Update Query like
update table1 set field1='abc' where field4='someothervalue'
then it is working fine
Can any one has idea how can I execute the queries like above using cfquery?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果您可以尝试使用 cfqueryparam 作为您的值,则不必使用 PreserveSingleQuotes。它还可以防止 SQL 注入。
If you can try using cfqueryparam for your values and you won't have to use PreserveSingleQuotes. It also protects against SQL injection.
您是否尝试将更新包含在 PreserveSingleQuotes 中?
Did you try wrapping your update within PreserveSingleQuotes?
您确定您的子选择语句返回 1 行吗?这取决于您运行的 RDMS,但我很确定并非所有数据库都支持此功能。我首先尝试直接在数据库上运行查询,看看它是否正确运行。
您可以通过在查询末尾设置限制 1 来强制 sql 仅返回 1 行,或者如果您的数据库不支持将 field1 包装在聚合中。
注意:如果您的字符串值是来自用户的参数,则应确保使用 cfqueryparam 来防止 SQL 注入。
Are you sure your subselect statement is returning 1 row. It depends on what RDMS you are running, but I'm pretty sure not all databases support this feature. I'd try running the query directly on your database first to see if it runs correctly.
You might be able to force sql to return only 1 row by putting a limit 1 on the end of your query, or if your database doesn't support it wrapping field1 in an aggregate.
Note: If your String values are parameters from the user, you should make sure to use cfqueryparam to protect against SQL injection.