On 2/9/16, Scott Robison <scott at casaderobison.com> wrote: > On Feb 9, 2016 3:16 AM, "Clemens Ladisch" <clemens at ladisch.de> wrote: >> > all text values are UTF-8 by default? >> >> Yes. It would be possible to configure databases to store text values >> as UTF-16, but nobody does this, and they would be converted >> automatically when using sqlite3_column_text(). > > Certainly one might change the type to UTF-16 if one is on a platform that > uses that type. Windows, Java, others support such strings natively. Just > use sqlite3_column_text16 to avoid UTF-8 conversions. > > At least, that is how I would expect it to work.
Every SQLite database file has a text encoding that applies to the entire file: one of utf8, utf16be, or utf16le. The database text encoding is stored in the header. You can see the encoding for a particular database using: sqlite3 DATABASE.db .dbinfo (NB: The ".dbinfo" command is relatively recent, so you'll want the latest version of sqlite3.exe for this to work.) All text store in the database file uses the database text encoding. *All Text*. So if your database encoding is UTF16 and you do "sqlite3_bind_text()" then SQLite automatically converts your UTF8 input into UTF16 before storing it. Or if you do "sqlite3_column_text()", then SQLite will convert from UTF16 to UTF8 before returning the answer. Obviously, in order to avoid unnecessary conversions, it works best if the database encoding matches the encoding most commonly used by your application. -- D. Richard Hipp drh at sqlite.org