Change inmemory db to file-based db

I was working on a data migration/cleansing app today. I use SQLiteDatabase as an inmemory db so that all the CSV imports and merges and cleansing would be done there. Finally, the user would have an option to export the db as a sqlite3 -file if required.

The strange thing is the following: I can create the inmemory db normally, insert databaserecords and do queries. I cannot however assign it with a folderitem using db.DatabaseFile = exportfolderitem and db.CreateDatabaseFile. If I do that of the database that is a global property, the result is an empty file with size of about 3 kB. I can still do queries on that object though and see that it has 21 columns and 21000 records.

I can of course forget the idea of using the db as inmemory db and instead of create always a file but the behaviour seemed strange. Why wouldn’t I be able to assign a file on database object later on?

are you attempting to change from In-Memory to filebase WHILE the database connection is active?
That you cannot do… you must close the connection and reopen it.
And doing so does NOT automatically transition the data from one place to the other if that is what you are looking for. to do that you need TWO connections, or a file copy.

Have a look at this command SQLiteDatabase.AttachDatabase.

Thanks for these! The AttachDatabase is close but I understood it would require the file actually existing and being a valid sqlite3 -file. So what I’d want to do is sort of other way round. The backup method actually would do the thing and would also allow versioning.