Name

encoding — Control the default text encoding

Common Usage

PRAGMA encoding;
PRAGMA encoding = format;

Description

The encoding pragma controls how strings are encoded and stored in a database file. Any string value that is recorded to the database is first re-encoded into this format.

The format value can be one of 'UTF-8', 'UTF-16le', or 'UTF-16be'. Additionally, if the value 'UTF-16' is given, either 'UTF-16le' or 'UTF-16be' will be used, as determined by the native endian of the processor. Any version of SQLite running on any platform should be able to read a database file, regardless of the encoding.

The encoding can only be set on the main database, and only before the database is initialized. All attached databases must have the same encoding as the main database. If ATTACH is used to create a new database, it will automatically inherit the encoding of the main database. If the main database has not been initialized when ATTACH is run, it will automatically be initialized with the current default values before the ATTACH command is allowed to run.

See Also

ATTACH DATABASE [SQL Cmd, Ap C]

Get Using SQLite now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.