On Thu, May 7, 2015 at 11:03 AM, Scott Hess <shess at google.com> wrote: > On Thu, May 7, 2015 at 10:53 AM, Paul Sanderson <sandersonforensics at > gmail.com> wrote: >> I am contemplating a change to a program whereby a database is >> initailly created in memory and then later if my users choose they can >> save it to disk and then switch to using the disk based DB. >> >> I can obviously create a new disk based db, iterate through >> sqlite_master and then populate each table. But I just wondered >> whether anyone had any suggestions of a better way of doing this? > > You could use the backup API to backup the in-memory database to disk.
Additionally, VACUUM is implemented essentially as "Create a new database, copy everything over using SQL commands, replace the original database". If you decide to go the route of scanning sqlite_master and populating things that way, I strongly recommend using the VACUUM implementation as a guide, since it will have already considered various interesting edge cases and optimizations. -scott