I have 2 database files in my iOS app:
Documents
folder)I need to run a SQL query to copy from the original database to the user's, something like:
INSERT INTO UserDatabase.MyTable
SELECT * FROM OriginalDatabase.MyTable;
Is this possible from SQLite running on iOS? The problem is the two databases are in different folder. I would like to avoid doing this work in code (C#) which is the obvious way to do it, just much slower.
My app is written with C#/MonoTouch, but that is probably irrelevant.
Solved with @Peter M's link.
Here is the SQL to do this on iOS:
ATTACH DATABASE '../YourApp.app/YourDatabase.db' AS OriginalDatabase;
INSERT INTO Main.MyTable
SELECT * FROM OriginalDatabase.MyTable;
DETACH DATABASE OriginalDatabase;
Note the use of Main
, this is the database you are connected to with SqliteConnection
, in my case it was located in the Documents
folder.
You can do anything you need against the OriginalDatabase
, joins, subselects, etc.
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