user1079655
user1079655

Reputation: 107

updating permanent db using in-memory db

How can I update a big permanent database by a small in-memory database? I have an application that has a big permanent db(on hard disk) and small in-memory db(in RAM). During run time of my application in-memory database is filled up and at the end of the run it updates permanent db.

Does anyone know how I can do this?

Upvotes: 0

Views: 534

Answers (1)

user610650
user610650

Reputation:

You can achieve this with ATTACH DATABASE:

http://www.sqlite.org/lang_attach.html

EDIT 05.12.2011:

Here I create an on-disk database:

[someone@localhost ~]$ sqlite3 some_big_db
SQLite version 3.7.5
Enter ".help" for instructions
Enter SQL statements terminated with a ";"
sqlite> create table t1 (a int, b text);

Here I open an in-memory database, create a table, populate it, attach the on-disk database, and copy the in-memory database table's content in the on-disk database table:

[someone@localhost ~]$ sqlite3 
SQLite version 3.7.5
Enter ".help" for instructions
Enter SQL statements terminated with a ";"
sqlite> create table t2 (a int, b text);
sqlite> insert into t2 values (1, 'aa');
sqlite> insert into t2 values (2, 'bb');
sqlite> attach database some_big_db as big_db;
sqlite> insert into t1 select * from t2;

Here I open the on-disk database and select its table's content:

[someone@localhost ~]$ sqlite3 some_big_db 
SQLite version 3.7.5
Enter ".help" for instructions
Enter SQL statements terminated with a ";"
sqlite> select * from t1;
1|aa
2|bb

Upvotes: 5

Related Questions