I try to run script (.read FILE
) that has UTF-8 strings. I used pragma command:
PRAGMA encoding="UTF-8";
But I get wrong characters. If I create table and insert values by myself, everything works right. What should I do to run script properly?
By the way, I checked a lot of questions/articles on stackoverflow and other resources + read documentation. I tried some methods, for example, to use chcp 65001
in Windows cmd
and then opened sqlite3
in current window. But it didn't help.
The default encoding will be UTF-8 for databases created using sqlite3_open() or sqlite3_open_v2(). The default encoding for databases created using sqlite3_open16() will be UTF-16 in the native byte order.
SQLite fully supports storage and retrieval of Unicode strings, encoded as UTF-8, UTF-16LE, or UTF-16BE. The only aspect of Unicode that SQLite does not support is case-insensitive matching of characters.
Fortunately UTF-8 is the default per sé. When reading an XML document and writing it in another encoding, mostly this attribute will be patched too.
UTF-8 is the most widely used way to represent Unicode text in web pages, and you should always use UTF-8 when creating your web pages and databases. But, in principle, UTF-8 is only one of the possible ways of encoding Unicode characters.
The PRAGMA encoding
setting does not change how you use the SQLite API. And the encoding of an existing DB cannot be changed.
Don't use it.
The sqlite3.exe
command-line shell does not work with UTF-8 characters. (Except maybe in the latest version.)
Don't use it.
If your own scripts and applications use strings encoded in UTF-8, and if you use any tool except sqlite3.exe
to check the resulting DB, then it will work.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With