I need to create a SQLite DB for my application. I'll need to store text in several European languages, so there will be plenty of accented characters and other weird marks. I'm extending SQLiteOpenHelper
.
Inspecting the .db file I noticed there's an extra table named android_metadata
. There's a single column named locale
, which is set to "en_US" by default in my simulator.
I've readed the SQLite section in the developer guide, and also the javadocs for SQLiteOpenHelper
and SQLiteDatabase
, searched in SO and in Google, but nowhere I could find what is the correct place to set the locale to the DB, or if it is really neccesary. Guessing it should be done at DB creation, I tried calling db.setLocale
in the helper's onCreate
method, but I'm, getting this exception:
BEGIN TRANSACTION failed setting locale
FATAL EXCEPTION: Thread-9
android.database.sqlite.SQLiteException: cannot start a transaction within a transaction
at android.database.sqlite.SQLiteDatabase.native_setLocale(Native Method)
at android.database.sqlite.SQLiteDatabase.setLocale(SQLiteDatabase.java:1950)
This is how my method looks:
public class MyOpenHelper extends SQLiteOpenHelper {
@Override
public void onCreate(SQLiteDatabase db) {
db.setLocale(new Locale("en","EN"));
...
}
...
}
And here are my questions:
- Do I really need to set the locale to the DB? I don't really need to get the queries sorted out of the box, as I can always sort the results myself later.
- Where should I call
setLocale
?