I have two instances of SQLiteDatabase database. And I need to copy data from one to another.
I need to execute this query:
INSERT INTO `toDB`.`tableName` SELECT * FROM `fromDB`.`tableName`
so, How can I do this my database instances? How to replace toDB and fromDB ?
Never tried that but it should work this way:
you have to ATTACH the other database at SQLite level so sqlite can access it directly.
For example you open the database that shall be the toDB and you issue the following command (via execSQL)
ATTACH DATABASE '/data/data/your.package/databases/dbname.db' AS fromDB
you should have access to the other database now and can do
INSERT INTO main.tableName SELECT * FROM fromDbB.tableName
the database you opened originally has the name "main" automatically.
You can and should get the path to your databases via Context#getDatabasePath since there is no guarantee that this path is the same on all devices.
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