Sqlite SQL格式化输入函数splite3_mprintf
来源:互联网 发布:西咸新区大数据交易所 编辑:程序博客网 时间:2024/04/30 11:56
sqlite中,
在使用sql语句写入字符串数据时,
由于字符数据中可能隐含转义字符,
如果对于他们不作处理,执行时,exec函数将不识别,或者造成注入攻击
这个时候sqlite_mprintf(),
应该就是必须使用了,配合‘%q’将字符数据中的转义字符,直接转换,
就不用担心字符串中含有‘单引号,这样造成sql语句不识别的问题。
For example, assume the string variable zText contains text as follows:
char *zText = "It's a happy day!";
One can use this text in an SQL statement as follows:
char *zSQL = sqlite3_mprintf("INSERT INTO table VALUES('%q')", zText);sqlite3_exec(db, zSQL, 0, 0, 0);sqlite3_free(zSQL);
Because the %q format string is used, the '\'' character in zText is escaped and the SQL generated is as follows:
INSERT INTO table1 VALUES('It''s a happy day!')
This is correct. Had we used %s instead of %q, the generated SQL would have looked like this:
INSERT INTO table1 VALUES('It's a happy day!')
0 0
- Sqlite SQL格式化输入函数splite3_mprintf
- Sqlite SQL格式化输入函数splite3_mprintf
- scanf函数格式化输入
- sql 时间格式化函数
- sql 格式化 日期函数
- sql 时间格式化函数
- SQL 日期格式化函数
- sql 时间格式化函数
- sql 时间格式化函数
- SQL 时间格式化函数
- linux 格式化输出输入函数
- 54_格式化输入函数
- C语言scanf()函数:格式化输入函数
- C语言scanf()函数:格式化输入函数
- Sql Server 日期格式化函数
- Sql Server 日期格式化函数
- Sql Server 日期格式化函数
- SQL CONVERT函数 时间格式化
- navigation的pushViewController卡顿问题
- 封装同步的UIActionSheet
- linux0.11进程调度分析
- 混迹CSDN也有一些时日了,决定从今天开始记录我的程序生涯中的点点滴滴
- 17230 计算轴承半径[C]
- Sqlite SQL格式化输入函数splite3_mprintf
- I2C总线
- 紫外线消毒器:紫外线杀菌消毒装置的技术要求详解
- Java虚拟机学习 - 体系结构 内存模型
- NSSortDescriptor:Array,Set和Core Data中排序的实现
- 走马观花: Linux 系统调用 open 七日游(一)
- WIFI基本知识整理
- 亿级Web系统搭建——单机到分布式集群
- 微信支付奇葩问题 system:access_denied