Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQLite UTF-8 encoding

Tags:

sqlite

utf-8

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.

like image 410
Keltar Helviett Avatar asked Jul 20 '16 13:07

Keltar Helviett


People also ask

What encoding does SQLite use?

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.

Does SQLite support Unicode?

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.

Is UTF-8 the default encoding?

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.

What is UTF-8 encoding used for?

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.


1 Answers

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.

like image 133
CL. Avatar answered Oct 03 '22 12:10

CL.