apr_dbd_escape
来源:互联网 发布:中电海康研究院 知乎 编辑:程序博客网 时间:2024/05/29 18:55
最近发现 apr_dbd_escape将 ‘ (单引号)转义成 \\' 而 apr_dbd_pvquery 将 \\' 解释成 \' 于是 当你想执行
insert into account ( username ) values ( "abc'def" )时,用apr_dbd_escape转义后会变成插入 abc\'def, 而不用apr_dbd_escape转义反而是期待的结果,插入了 abc'def
以上现象与我先前的理解有出入。
1. 我知道 escape_string_for_mysql 将会对 ‘ , “ , \n , \r , \ 进行转义。从源码看来, apr_dbd_escape 调用的就是escape_string_for_mysql 不应该出现 ' 转成 \\' , 应为 \'
2. apr_dbd_pvquery 在执行一些带有‘ 或 “ 语句, 应该转义。 但结果发现不转义反而出现正确的结果。
经查,我在apr_dbd_pvquery中用了prepared statement. 在这种情况下,apr_dbd_pvquery 在执行一些带有‘ 或 “ 语句, 无需转义。详见:
http://stackoverflow.com/questions/2003572/how-can-i-escape-single-and-double-quotes-in-sql-prepared-statement
里面某牛人(Bill Karwin)如是描述:
If the DBI is "emulating" prepared statements by interpolating the variables into the query string, then DBI should handle the correct escaping logic so you don't have to. Let the experts (those who write and test DBI) worry about how to do it.
我先前理解 2 是错误的。
- apr_dbd_escape
- SharePoint 2013使用Exchange2013 配置传入电子邮件
- 最小生成树之Kruskal算法的实现
- oracle 数据类型
- Android--ListView 更高效的使用 Adapter
- Android TextView的各种属性
- apr_dbd_escape
- JavaSE基础复习:面向对象知识点二
- 函数参数中的引用
- 虚拟机启动,硬盘很慢
- 关于ORACLE的UPDATE更新多表的问题
- 64位Eclipse运行时提示“Failed to load the JNI shared library \Java\jre6\bin\client\jvm.dll”的一个解决方案
- 并查集的实现
- Sharepoin学习笔记—架构系列—Sharepoint服务(Services)与服务应用程序框架(Service Application Framework) 1
- 在oracle9i数据库中排除某些表做owner级别导出