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.
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.
The Android SDK includes a sqlite3 shell tool that allows you to browse table contents, run SQL commands, and perform other useful functions on SQLite databases.
Date and Time Datatype SQLite does not have a storage class set aside for storing dates and/or times. Instead, the built-in Date And Time Functions of SQLite are capable of storing dates and times as TEXT, REAL, or INTEGER values: TEXT as ISO8601 strings ("YYYY-MM-DD HH:MM:SS. SSS").
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.
You need to make use of the encoding PRAGMA
:
PRAGMA encoding = "UTF-8";
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.
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