SQLite on iOS - SQL to copy from one file to another

I have 2 database files in an iOS app:

  • Source database (read-only in the home directory of my application)
  • User database (stored in the user folder Documents)

I need to run an SQL query to copy from the source database to the user one, something like:

INSERT INTO UserDatabase.MyTable
SELECT * FROM OriginalDatabase.MyTable;

Is this possible from SQLite running on iOS? The problem is that the two databases are in different folders. I would like to avoid doing this work in code (C #), which is the obvious way to do this, much slower.

My application is written using C # / MonoTouch, but that probably doesn't matter.

+3
source share
1 answer

@Peter M.

SQL, iOS:

    ATTACH DATABASE '../YourApp.app/YourDatabase.db' AS OriginalDatabase;

    INSERT INTO Main.MyTable
    SELECT * FROM OriginalDatabase.MyTable;

    DETACH DATABASE OriginalDatabase;

Main, , , SqliteConnection, Documents.

, , OriginalDatabase, , ..

+3

All Articles