Encoding problems during INSERT with Sqlite3 C++ and VisualStudio2010 Encoding problems during INSERT with Sqlite3 C++ and VisualStudio2010 sqlite sqlite

Encoding problems during INSERT with Sqlite3 C++ and VisualStudio2010


I found the solution. It was nothing related to encoding, as I thought because of the characters being strangely represented in the DB browser and also nothing related to the length.

The problem was in the last parameter of the binding. Where i pass SQLITE_STATIC, I should have passed SQLITE_TRANSIENT, as the object returned by the calls I want to bind are possibly destructed before the query is executed. Just as it is explained in this other question:

sqlite3_bind_text SQLITE_STATIC vs SQLITE_TRANSIENT for c++ string


I think sqlite reference is quite clear about the API usage.

In those routines that have a fourth argument, its value is the number of bytes in the parameter. To be clear: the value is the number of bytes in the value, not the number of characters.

As per your usage,

sqlite3_bind_text(stmt, 2, newShop.GetName().c_str(), -1, SQLITE_STATIC); the 4th arguement is -1. However it should be either newShop.GetName().length or strlen(newShop.GetName().c_str())`

Note : be careful when you deal with string with multi-wide chars. Where strlen(chinese string) ! = chinese string.len . Refer here for more details.