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.
- 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
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
精彩评论