0

I'm trying to update a specific text column(WVARCHAR) on sqlite row using sqlite3_bind_text16() on my C program but unfortunately, only the strings that contains only ascii encoded characters like L"e" are updated correctly, but the other strings containing unicode characters like L"é"are updated having the non-ascii characters not stored correctly. here is example how I used the function:

sqlite3_bind_text16(stmt, 1, L"e", -1, SQLITE_STATIC); //e is stored correctly
sqlite3_bind_text16(stmt, 2, L"é", -1, SQLITE_STATIC); //é not stored correctly: modified

I tested that by doing select command using sqlite shell for my program's sqlite database file.

so how to fix that?

user3457200
  • 129
  • 1
  • 8
  • What happens to the non-ASCII characters? – CL. May 14 '14 at 19:10
  • http://picsee.net/upload/2014-05-14/42d9402a739d.png – user3457200 May 14 '14 at 19:27
  • The Windows command shell does not handle SQLite's UTF-8 characters correctly. Use any other program to show the database contents, or show the output of `SELECT hex(MyColumn) FROM taxdeclarations;`. – CL. May 14 '14 at 19:31
  • so you want to say, that there is nothing wrong from the side of my C program? – user3457200 May 14 '14 at 19:34
  • 1
    If you used only the Windows command shell, this might be the case. – CL. May 14 '14 at 19:34
  • The Microsoft compiler has [a bug](http://connect.microsoft.com/VisualStudio/feedback/details/431244/std-ostream-fails-to-write-utf-8-encoded-string-to-console) that [breaks UTF-8 I/O](http://alfps.wordpress.com/2011/11/22/unicode-part-1-windows-console-io-approaches/); the [workaround](http://alfps.wordpress.com/2011/12/08/unicode-part-2-utf-8-stream-mode/#utf8_mode_narrow_fail_fixed) is ugly and nonportable. – CL. May 14 '14 at 20:11

1 Answers1

0

Issue the following PRAGMA to the database prior to updating:

PRAGMA encoding = 'utf8';

This should ensure sqlite is updating non-ASCII characters correctly.

mfro
  • 3,286
  • 1
  • 19
  • 28
  • It is not possible to change the database encoding after the database has been created, and this encoding setting does not change the encoding of strings used in the API. – CL. May 14 '14 at 19:32