Just like http://www.sqlite.org/backup.html
I wanna load db into memory, all operations will be done in memory, and save memory db to disk before application exit.
QxOrm is too slow to open & close db every time from disk when I call qx::dao::XXX.
Help pls. Thank you!
-------------------------
I tried this code, but failed to copy data to memory.
try
{
// Parameters to connect to database
qx::QxSqlDatabase::getSingleton()->setDriverName("QSQLITE");
qx::QxSqlDatabase::getSingleton()->setDatabaseName(":memory:");
qx::QxSqlDatabase::getSingleton()->setHostName("localhost");
qx::QxSqlDatabase::getSingleton()->setUserName("root");
qx::QxSqlDatabase::getSingleton()->setPassword("");
// Disable debug output
//qx::QxSqlDatabase::getSingleton()->setTraceSqlQuery(false);
}
catch(...)
{
return false;
}
// File 2 memory
QSqlDatabase db = qx::QxSqlDatabase::getSingleton()->getDatabase();
QVariant v = db.driver()->handle();
if (v.isValid() && qstrcmp(v.typeName(), "sqlite3*") == 0)
{
// v.data() returns a pointer to the handle
sqlite3 *handle = *static_cast<sqlite3 **>(v.data());
if (handle != 0)
{
// check that it is not NULL
int result = loadOrSaveDb(handle, path.toStdString().c_str(), false);
if(result != SQLITE_OK)
{
throw std::exception("File 2 memory error.");
}
}
}