Unable to set SQLiteDatabase encoding to anything but UTF-8

I am working on a problem when I need to bind one sqlite database to another. One of the databases is created by my application, and the other is downloaded from a remote server. I would rather get it in a legal data format (like JSON), but I can't control this aspect.

The problem is that the encoding of the loaded sqlite file is UTF-16le. The local file is UTF-8 (Android by default). I can read both files perfectly on my own, but SQLite only allows ATTACH operations when encoding.

The solution should be as simple as using UTF-16le encoding when I create a local database, but it seems that the encoding is always set before I get the database object, and I cannot change it. I am using SQLiteOpenHelper, and I suggested that all PRAGMA statements should be executed in onConfigure () as follows:

@Override 
public void onConfigure(SQLiteDatabase db) { 
    db.execSQL("PRAGMA encoding = \"UTF-16le\""); 
}

When I check the encoding after this point, there will always be UTF-8.

Log.d(TAG, DatabaseUtils.dumpCursorToString(db.rawQuery("PRAGMA encoding", null)));

result:

04-12 11:10:07.116: D/MainActivity(10743): >>>>> Dumping cursor android.database.sqlite.SQLiteCursor@b3636fd0
04-12 11:10:07.116: D/MainActivity(10743): 0 {
04-12 11:10:07.116: D/MainActivity(10743):    encoding=UTF-8
04-12 11:10:07.116: D/MainActivity(10743): }
04-12 11:10:07.116: D/MainActivity(10743): <<<<<

I even tried to create a database in memory and set its encoding, but it always reports UTF-8:

SQLiteDatabase db = SQLiteDatabase.create(null);
db.execSQL("PRAGMA encoding = \"UTF-16le\"");

I am a little confused because I can open these UTF-16le encoded databases and their encoding is reported correctly, but I cannot create it on the device. Is there any way to set the encoding of the database when I create it?

+5
source share
2

kludgy. , UTF-16le . , ( SQLiteOpenHelper) .

0

Android- sqlite UTF-8 UTF-16.

?

+1

All Articles