현시욱 wrote:
> Hello,
> 
> Hi, I'm a student studying SQLite. I am trying to create a memory DB and
> dump it into a file when the program closes, and opening the memory DB back
> from a file when SQLite is first executed. Actually there is a patch
> regarding this feature in SQLite-Wiki index, I downloaded it and tried to
> use it but it just wouldn't work since the patch was made for previous
> versions of SQLite.(I'm currently using 3.5.7). - The patch is available at
> http://www.kordelle.de/sqlite/ -
> After compiling using the patch, I got stuck in some errors.
> 
> First, it couldn't find 'sqlite3_write_to_file'
> 
> Second, it couldn't find a "pager" variable in the structure "Btree", which
> I found there actually isn't such member.
> 
> I'm sure there has been a lot of change in SQLite since that patch has been
> released. A friend of mine tried to find a previous version of SQLite,
> 3.2.2, but he couldn't find it. If 3.2.2 is too old to find, I'm curious if
> it's possible to get a version between 3.2.2 and 3.3.x?
> 
> If not, maybe someone might give me a tip about editing the patch to make it
> work. That would be really helpful too!
> 

I would suggest that you review your requirements. Why do you want to 
use a memory database for data that you want to be persistent between 
program executions?

You would probably be better off using only a file based database. It 
will provide the persistence automatically and simplify your program by 
eliminating the need to copy data back and forth during initialization 
and termination. There is really very little difference in performance 
between a memory and a file based database, since SQLite and the OS 
cache the database file in memory for fast access anyway.

That patch you have found is very old and probably can't be made to work 
without a very good knowledge of the SQLite's internals. Furthermore, 
even if you do get it to work with the current SQLite, it will probably 
break again if you try to update to a future version of SQLite.

If you really insist on using two databases, one in memory and the other 
in a file, then you should use the public interface of SQLite to copy 
the data back and forth. You can do this in SQL by attaching one 
database to the other and then using statements like this

   create db1.table as select ... from db2.table

to copy the data. You may need to execute create index statements to 
recreate indexes in the target database that are present in the source 
database. When copying data back out to the file, ensure all the changes 
are done in a transaction so the database will be intact if the OS 
crashes or you loose power during the copy operations.

You could also use the C API functions to dump all the data in the 
memory database into a SQL script file that can be executed to recreate 
the database. This is what the ssqlite3 shell's .dump command does. You 
can copy the source for that function (it's public domain open source 
after all). Doing this you would execute the script to populate the 
memory database on startup, and dump the database to a new script file 
(which is then swapped for the existing script file,again to avoid 
destroying the existing file on a crash or power fail) during shutdown.

HTH
Dennis Cote




_______________________________________________
sqlite-users mailing list
sqlite-users@sqlite.org
http://sqlite.org:8080/cgi-bin/mailman/listinfo/sqlite-users

Reply via email to