On Thu, 3 Feb 2005, Andrew Lukasik wrote:

>
>I am currently using sqlite3 as an in-memory (:memory:) database. Is it
>possible to write a snapshot of the in-memory database to a disk file? I'd
>like to then be able to use the sqlite3 binary to paw over the data.
>I realize I could simply change the file name from :memory: if I wanted to
>do a debugging session during development. But what I'm after here is a way
>to do debugging/viewing on an in-memory production database. I'd even be
>intersting to take this snapshot for report generation etc... I've seen a
>thread here about having multiple binaries connect to a shared in-memory
>sqlite database. Is this functionality avaliable. I suppose this would work
>as well.
>/Andrew

Check out the attach command:
http://www.sqlite.org/lang_attach.html

Using this, you can attach a disk database, then dump the database to that
using "insert into ... select ..." to select the snapshot from your
:memory: database.

The in memory database idea was to use a database file in /tmp, which is
backed by virtual memory on Solaris, Linux with tmpfs or BSD with mfs.

You're probably better off using a disk database for debugging, and only
use :memory: once you're satisfied with functionality, and have an
alternate mechanism for archiving and reporting, such as using the dump
code from the SQLite shell to write a dump of the in memory database when
opening a fifo perhaps. Consider:
0. Create fifo:
  $ mkfifo /tmp/.<app>.syncfifo
1. Spawn thread in application to open fifo in write mode. This will hang
   until something opens the fifo for read.
2. cat from the fifo the dump to create a new disk database.
  $ cat /tmp/.<app>.syncfifo | sqlite newdb
3. Run report from newdb.
4. goto 1.

Or you could listen on a socket, and dump the database when someone
connects to the socket.

The benefit of a dump format is that it can be used in any database as
long as SQLite proprietry functionality is not used in the schema.

Christian


-- 
    /"\
    \ /    ASCII RIBBON CAMPAIGN - AGAINST HTML MAIL
     X                           - AGAINST MS ATTACHMENTS
    / \

Reply via email to