CFQUERY 没有正确转义单引号 [英] CFQUERY Not escaping single quotes properly

查看:18
本文介绍了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"/>)

供参考:

这篇关于CFQUERY 没有正确转义单引号的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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