On Tue, Sep 01, 2009 at 01:46:03PM -0500, Jeff Godfrey scratched on the wall:

> The issue lies in my starting point.  The persistent storage of my 
> SQLite database file isn't as a separate, disk-based file as it would 
> normally be.  Instead, it's stored as a stream inside a "container file" 
> (an MS "DocFile").  Via C#, I can retrieve the stream that is the SQLite 
> database, which ultimately results in the stream being stored in-memory 
> as a C# byte array.

  No, I  understand.  Just write a Virtual File System module that
  talks to your byte-array.  When you get a "write" call from the
  SQLite engine, you copy data from the SQLite buffer to your
  bite-array object at the requested offset.  "Reads" are just copies
  from the byte array to the SQLite buffers.
  
  You'll have to keep track of where the end of the array is, and
  expand the array if SQLite asks to write to an offset that is
  beyond the current array size, but otherwise this should be fairly
  straight forward.  The VFS module itself wouldn't do any actual I/O,
  it would only talk to the byte-array as if it was a memory-mapped
  file (without the file).

  When all is said and done and SQLite closes the database connection,
  you can stash the modified byte array back into whatever storage
  repository you're using.  (For example, a BLOB of another database.)

  Using a custom VFS there is no need for conversions or a bulk copy of
  the whole database image from your byte array into some other format
  (including an on-disk file).  You can just have the SQLite engine "talk"
  directly to your byte array.  Depending on the flexibility of your
  back-end storage container, you might even be able to have the SQLite
  engine speak directly to that.

  The only trick is that SQLite would have to initiate the open.  So
  you'd need someway to map "filenames" to byte-array objects.  There
  are a number of ways to solve this problem, however, depending on the
  configuration of your application, including having your backend open
  a specific byte array no mater what filename is requested.  If you're
  controlling both sides, that's might be the easiest thing to do.

   -j


-- 
Jay A. Kreibich < J A Y  @  K R E I B I.C H >

"Our opponent is an alien starship packed with atomic bombs.  We have
 a protractor."   "I'll go home and see if I can scrounge up a ruler
 and a piece of string."  --from Anathem by Neal Stephenson
_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to