Dan
Dan

Reputation: 16246

Make sure the SQLite on Android uses UTF-8 as a charset

I am developing an Android application using SQLite as backend.

I want to make sure all the tables in the database use UTF-8. How can I achieve that?

I have tried:

CREATE TABLE myTable (_all_columns_definitions_) DEFAULT CHARSET=utf8;

but a syntax error arose.

Upvotes: 15

Views: 36203

Answers (3)

Marco C
Marco C

Reputation: 3213

By default Android SQLite uses UTF-8. I had the same problem with special characters, but because when I populated the database on the first launch I used a txt file with another charset.

Upvotes: 2

Martin v. Löwis
Martin v. Löwis

Reputation: 127467

Given that sqlite only supports UTF-8 and UTF-16 as the encodings, you would have noticed if Android would create databases in something other than UTF-8. sqlite3_open defaults to create the database in UTF-8, and that is what Android is likely to use.

Upvotes: 20

Alix Axel
Alix Axel

Reputation: 154573

You need to make use of the encoding PRAGMA:

PRAGMA encoding = "UTF-8";

Upvotes: 3

Related Questions