开发者

Escaping string for SQL in C++

I am searching a simple "addslashes" function for a program t开发者_Go百科hat must save in a sqlite database some information.

Thanks.


Instead of trying to re-implement addslashes, you should instead look into using prepared statements. They're simpler, faster, and easier.


  1. I'd suggest to use prepared statement and data binding to query so you would not need escaping or use a library like CppDB or SOCI to do it easily
  2. Sqlite3 uses SQL standard quites, so for escaping text you need to "double the quotes" for blob you need hexadecimal representation, i.e.

    C string: char const *s="I'm" -> SQL: 'I''m'
    C blob  : char s[2]={0xFF,0}  -> SQL: x'FF00'
    

    See: http://www.sqlite.org/lang_expr.html


I think its echo " \\hi "; - ouput \hi

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜