Discussion:
Database Memory Stream
Chris Sonon
2012-10-05 12:47:42 UTC
Permalink
Hello,

I am currently developing a program that will use an sqlite database and I would like to know if it is possible to load a database from a memory stream in c#?

I would like to house my database in a ZIP file and extract the database to a memory stream and then open it directly from the memory stream? Is this possible? If so, how?

Thank you,
Chris

Christopher Sonon | Application Engineer | CEPDM | CWPDM | CSWST
ModernTech<http://www.moderntech.com/> |1626 Downtown West Blvd. | Knoxville | TN | 37919 | USA
Phone: 865.934.5329 | Fax: 865.934.5353

"If you want to improve, be content to be thought foolish and stupid." Epictetus
"If we find ourselves with a desire that nothing in this world can satisfy, the most probable explanation is that we were made for another world." CS Lewis

Solidworks Technical Support | solidworks.support-iRthilafW20qDJ6do+/***@public.gmane.org<mailto:solidworks.support-iRthilafW20qDJ6do+/***@public.gmane.org> | 1.877.553.9001
Live Technical Support | Monday - Friday 8-5 Eastern Time | ModernTech GoToAssist<http://gotoassist.com/ph/moderntech>
Roger Binns
2012-10-06 05:36:31 UTC
Permalink
Post by Chris Sonon
I would like to house my database in a ZIP file and extract the
database to a memory stream and then open it directly from the memory
stream? Is this possible? If so, how?
You can get a zipvfs from the SQLite team:

http://www.hwaci.com/sw/sqlite/zipvfs.html

You can do it yourself with the C api - I don't know if the C# wrapper is
fully equivalent. It is also most likely the the zipvfs from the SQLite
team will be cheaper unless your time is worth nothing.

If you want to do it yourself, there are cheap hacks like extracting to a
temporary file and opening that. You should also be able to use the
backup API to copy a temporary file to memory. If temporary files are not
acceptable then you can write a VFS that exposes the zip file. Again the
backup API can be used to copy the database, or you could just use your
zipvfs directly.

The VFS operates at the level of the database file - for example there are
methods for reading and writing blocks of the files. SQLite also has a
virtual table mechanism which operates at a higher level - rows and
columns. You can use SQL while supplying the underlying data to operate
on. This approach may be more applicable if the data in the zip file is a
higher level.

And lastly you can store SQL in the zip file and just run it against a
memory database.

Roger

Loading...