Keith Herold wrote:
> Is there a fast way to dump the in-memory db to disk, *and* periodically
> reload the file into an in-memory db?
>

The ATTACH command can be used for this.

Suppose you do an sqlite_open() on the in-memory database
and you want to transfer the complete contents of an
in-memory table XYZ to an on-disk database named "abc.db"
You can do something like this:

   ATTACH 'abc.db' AS external;
   BEGIN;
   DELETE FROM external.xyz;
   INSERT INTO external.xyz SELECT * FROM xyz;
   COMMIT;
   DETACH external;

The same technique works in reverse to load an in-memory
table from disk:

   ATTACH 'abc.db' AS external;
   BEGIN;
   DELETE FROM xyz;
   INSERT INTO xyz SELECT * FROM external.xyz;
   COMMIT;
   DETACH external;

Use WHERE clauses creatively if you only want to transfer
part of the data.

Note that it is not necessary to ATTACH and DETACH every
time you want to do this.  If you are always using the
same external database file, you can just ATTACH it once
when you open the in-memory database and it will always
be there for you.

--
D. Richard Hipp -- [EMAIL PROTECTED] -- 704.948.4565


--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to