I created in-memory database in Android. I put null in name parameter in SQLiteOpenHelper constructor:
SQLiteOpenHelper(context, null, null, 1);
Also I created some doc_orders_products table in the in-memory db.
Now I’m trying attach this in-memory db to my main on-disk db.
What name of in-memory db should I use in ATTACH command?
I tried:
mainDB.execSQL("ATTACH DATABASE ':memory:' AS temp_db");
and
mainDB.execSQL("ATTACH DATABASE '' AS temp_db");
Both ATTACH command performs well even when in-memory db isn’t created at all.
But when I try get access to tables in the in-memory db, they are not present. I get exception. E.g.:
10-11 14:07:46.782: E/AndroidRuntime(2107): Caused by:
android.database.sqlite.SQLiteException: no such table:
temp_db.doc_orders_products (code 1): , while compiling:
INSERT INTO temp_db.doc_orders_products SELECT * FROM
main.doc_orders_products WHERE doc_id=3
Is it possible to attach in-memory db to on-disk db? What correct way is to do it?
Thanks.
Every new connection to an in-memory database creates a new, empty database.
So your
ATTACHcommands attached to a different database.What you should do is to use the
ATTACHcommand and then create your tables, through themainDBconnection, in thetemp_dbdatabase; e.g.CREATE TABLE temp_db.doc_orders_products(....