3

I have an in-memory sqlite database which I want to convert to a simple blob, and I want to do this preferably without using any serialization library.

I also use sqlite api backup calls to serialize it to disk, can this also be used for my purpose?

Or, is it possible to simply copy the database from memory to a char array in any other way? (Development is done using C++)

incrediblehulk
  • 409
  • 2
  • 11
  • so you have a SQLite DB in your memory and want to store it into another database as a blob? YO DAWG, I heard you like... (sorry could not resist). There is a good QT example http://www.qtcentre.org/threads/30080-Loading-and-saving-in-memory-SQLITE-databases - since it does not rely on QT functions heavily you should be able to figure a c++ only version with std::string and sqlite api. Anyhow, seen the backup example from sqlite? maybe overload a stream operator to match your need – Najzero Nov 29 '12 at 10:14
  • well, doesn't that qt example do what backup api does? what I want is convert the whole db to a char array that keeps that memory. basically memcopy'ing the db. the internals of backup api does what I want I guess, will need to look into that. – incrediblehulk Nov 29 '12 at 10:42

1 Answers1

3

SQLite does not give you direct access to the internal storage of an in-memory database.

You could implement your own VFS to create a 'file' interface for a blob, but just going through a (temporary) disk file sounds much easier.

CL.
  • 173,858
  • 17
  • 217
  • 259
  • thanks, I'm now looking into the vfs demo (http://www.sqlite.org/src/doc/trunk/src/test_demovfs.c), but I really hoped there would be an easier (or at least straightforward) approach. involving files is indeed super easy, but I'd rather not involve the file system. – incrediblehulk Nov 29 '12 at 13:58
  • A follow up: Is it possible to use multiple VFS layers in combination (I'm guessing, no)? Apparently there is already another layer used with another purpose. – incrediblehulk Nov 30 '12 at 13:31
  • It would be possible to stack VFSes, but this is not what you want (you want to store that DB *only* in the blob). Furthermore, SQLite's in-memory databases don't use a VFS at all. – CL. Nov 30 '12 at 14:14