'Is there a way to store and retrieve wide chars, wchar_t in sqlite using c++?

I am trying to store wstrings in sqlite. Does sqlite support the storage of wstrings? Below is code snippet

Person Table created using
CREATE TABLE Persons (     PersonID int,     LastName varchar(255),FirstName varchar(255));

int callback(void* NotUsed, int argc, char** argv, char** azColName) {
    int i;
    for (i = 0; i < argc; i++) {
        printf("%s = %s\n", azColName[i], argv[i] ? argv[i] : "NULL");
    }
    printf("\n");
    return 0;
}

int main()
{
   std::wstring firstName = L"Hello3ф";
   std::wstring lastName = L"World45£";
   sqlite3_stmt* stmt;

   int val = sqlite3_prepare16_v2(db, u"INSERT INTO Persons (PersonID,LastName,FirstName) 
   VALUES (4, ?, ?)", -1, &stmt, nullptr);
   if (val != SQLITE_OK) {
     fprintf(stderr, "Sqlite error: %s", sqlite3_errmsg(db));
     return 133;
   }
   sqlite3_bind_text16(stmt, 1, lastName.c_str(), -1, SQLITE_STATIC);
   sqlite3_bind_text16(stmt, 2, firstName.c_str(), -1, SQLITE_STATIC);
   val = sqlite3_step(stmt);
    if (val != SQLITE_DONE) {
        fprintf(stderr, "Sqlite error: %s", sqlite3_errmsg(db));
        return 134;
    }
    sqlite3_finalize(stmt);
   //To read the records
   std::string query = "select * from Persons";
   sqlite3_exec(db, query.c_str(), callback, NULL, &zErrMsg);
}

Output as below. callback is accepting only char** instead of wchar_t**. Can someone please suggest how I can safely store these values ?

PersonID = 4
LastName = World45£
FirstName = Hello3ф


Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source