Well that's kinda nifty!

Does the ATTACH lock the external file for as long as it is ATTACHed or only
when transactions are active?

If it is only locked during updates, this is probably the way I will do it,
since I can sacrifice a little bit of time for periodic writes to the DB
file.

--Keith

> -----Original Message-----
> From: D. Richard Hipp [mailto:[EMAIL PROTECTED] 
> Sent: Friday, March 12, 2004 4:37 PM
> Cc: [EMAIL PROTECTED]
> Subject: Re: [sqlite] Question about in memory db's
> 
> 
> 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]
> 


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

Reply via email to