简体   繁体   中英

sqlite3 unicode support in c++

std::ostringstream oss;
std::string s="תז";
oss << "insert into t values(" << s << ");"
this->sql = oss.str();    
rc = sqlite3_exec(c,this->sql.c_str(), callback, 0 , &zErrMsg);

this->sql.c_str() contains UTF-8 characters, after the execution of this line, if the data that inserted was unicode, this data in the database will be corrupted (one byte for each character instead of two bytes). How to add Unicode support?

I want to write תז to the database, the bytes written to the database are: fa e6 what needs to be written: d7 aa d7 96

Thanks.

UTF-8 is a variable-length encoding. ASCII characters use one byte per character; others use two to four bytes.

SQLite never changes the bytes in a string. The database contains the bytes fa e6 because that are the contents of your original string s .

You must ensure that your source code file is encoded in UTF-8, or explicitly convert the string from its actual encoding into UTF-8.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM