SQLite转义字符串c ++ [英] SQLite escape string c++

查看:706
本文介绍了SQLite转义字符串c ++的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

请考虑以下代码

char bar[] = "hello world \"One\", two, 'three'";
char *zSQL = sqlite3_mprintf("INSERT INTO stuff (`foo`) VALUES ('%q');", bar ) ; 
sqlite3_exec(db, zSQL, 0, 0, 0);
sqlite3_free(zSQL);
/* Produces a exception error */

问题是在SQL语句中转义。如果我在PHP中编程,我会使用像 sqlite_escape_string 这样的函数来转义字符串将它们插入到SQL查询中,但我似乎无法在C ++中找到等效的函数。我可以建立自己的sqlite_escape_string类似的函数,但我相信有一个已经写/测试...

The problem is that the quotes are not getting escaped in the SQL statement. If I was programing in PHP I would use a function like sqlite_escape_string to escape the strings before inserting them in the SQL query but I can not seem to find the equivalent function in C++. I could build my own sqlite_escape_string like function but i am sure there has to be one already written/tested...

有一个sqlite_escape_string()等效函数为c ++?

Is there a sqlite_escape_string() equivalent function for c++?

推荐答案

否。使用绑定的参数。

请参阅:

http://www.sqlite.org/c3ref/prepare.html

http: //www.sqlite.org/c3ref/bind_blob.html

这篇关于SQLite转义字符串c ++的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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