CFQUERY 没有正确转义单引号

编程入门 行业动态 更新时间:2024-10-25 11:23:24
本文介绍了CFQUERY 没有正确转义单引号的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

可能重复:Coldfusion 在字符串中构造数据库查询时添加额外引号

全部,

我正在尝试在插入期间使用 getter 来引用 bean.CF 没有正确转义 'form.title' 值中的单引号,因此我收到格式错误的 sql 错误.

I am trying to use a getter to reference a bean during an insert. CF is not escaping the single quote properly in the value in 'form.title' and therefore I am receiving a malformed sql error.

有什么想法吗?

这是代码.

<cfscript> form.title = "page's are awesome"; page = new model.page.page(argumentCollection = form);

<cfquery name="test" datasource="ksurvey"> insert into page(title) values('#page.getTitle()#') </cfquery>

推荐答案

如果你打算这样做,你需要 preserveSingleQuotes()

If you're going to do it that way, you need preserveSingleQuotes()

插入页面(标题)值('#preserveSingleQuotes(page.getTitle())#')

当然,插入关于如何使用 cfqueryparam 以避免 SQL 注入攻击的标准警告.

Of course, insert the standard caveat about how you should be using cfqueryparam to avoid SQL injection attacks.

插入页面(标题)值(<cfqueryparam value="#page.getTitle()#" cfsqltype="cf_sql_varchar"/>)

供参考:

  • cfquickdocs/cf9/#preservesinglequotes
  • cfquickdocs/cf9/#cfqueryparam

更多推荐

CFQUERY 没有正确转义单引号

本文发布于:2023-10-27 23:40:00,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1534868.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:正确   单引号   CFQUERY

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!