Using in-memory sqlite android

Grandpa picture Grandpa · Jul 25, 2012 · Viewed 13.4k times · Source


I've been reading, browsing, searching a lot on this, I've criss-crossed stackoverflow back and forth many times and I managed to narrow my problem as much as I could.

The only thing I do not understand, is how to fully use an in-memory SQLite database.

Here is my situation - I have an encrypted SQLite database which I decrypt during the loading of my application (this part works for sure). My class that interacts with the database works for sure with a plain database. So to make it short, everything is flawless with a plain DB which gets loaded from the internal phone memory, but I am not sure how or where to store the decrypted DB in memory so it would get interpreted as normal DB.

I guess I should put null instead of a name in super(context, null, null, 3); and use :memory: instead of a path in SQLiteDatabase.openDatabase(), but I still don't understand fully. It says it cannot find an android_metadata table, but I am certain the database is as it should be.

Hope I was clear on this :)

Answer

Diego Torres Milano picture Diego Torres Milano · Jul 25, 2012

SQLiteOpenHelper() will create an in-memory database if the name is null. Note that it will be created when you invoke getWritableDatabase().

Then you should insert your data.