http://www.sqlite.org/inmemorydb.html
Mentions the ability to create a temporary database that will be stored in memory until a file is necessary (if at all). It will also remove that file when finished automatically. This is achieved by providing a blank database name ""
.
rc = sqlite3_open("", &db);
I'm trying to do this within a QT4 based application using the QSQLDatabase
QSqlDatabase db = QSqlDatabase::addDatabase("QSQLITE");
db.setDatabaseName("");
bool ok = db.open();
Results in a failure to open the database.
I'm aware of the :memory:
option and using it is much faster in our application for small datasets. I would prefer something that will drop back to a file when necessary since we may have some large datasets.
I am making the assumption that allowing the database engine to cache to file when necessary will be more efficient that just letting the OS page the memory in and out.
I'm open to alternatives with the following requirements:
- Fast insert and lookup
- No file once application is closed
Update After going through some of the suggested SQLite performance suggestions I now have acceptable performance when using a file (TRANSACTIONS!).
I have not been able to figure out how to use sqlite3's built-in temporary file functionality.
I'm trying to use a QTemporaryFile, but for some reason they won't auto-delete the way the documentation implies they should. I have some more experimenting to do.