[pysqlite] Save memory database to file/load memory database from file

"Jason R. Coombs" <[email protected]> Thu, 24 Jul 2008 13:32:16 -0400
Newsgroups gmane.comp.python.db.pysqlite.user
Organization Innovative Management Concepts
Message-ID <[email protected]>
Gerhard wrote:
>Malcolm Greene wrote:
>> Is there a generic, best practice way to save an arbitrary memory
>> database to file and then later restore that file image to memory?
>
>I've always wondered what the use case for that is. Can you tell us why
>you want to do this?

I would like to do this for similar reasons.  I have a web application where 
the application data will be organized in a sqlite database unique to each 
user.  The user will upload the database when he begins a session and 
download it when he is done.  I want to manage the data entirely in memory 
because

    (a) the database size will be relatively small (on the order of a few 
megabytes),

    (b) there will be few users simultaneously using the system,

    (c) I want the data to expire when the user's session expires (which may 
occur as a timeout), so I intend to store the sqlite database in the user's 
server-side session.

    (d) I don't want to have to find a place to store the data on the disk, 
ensure that the permissions are correct, and remove files that have expired.

So, to be specific, I don't want to load/dump the in-memory database to/from 
a file, but instead to/from a stream.
It appears the API doesn't support what I'm trying to do.  Do you have any 
suggestions on how I might go about saving an in-memory database or 
initializing from a previously-saved database without touching the file 
system?

I understand I could use the aforementioned file-based technique to 
accomplish what I need, but that's a clumsy way to get at the raw data, when 
it presumably already exists in memory.

Regards,
Jason