Now I'm currently developing a password manager program. I have some encrypted .db file, after decrypting it as QByteArray I want to save it somewhere in RAM so I don't create temporary files. After it I need to load it to QSqlDatabase.
I have tried this:
QFile *f;
f = new QFile(":memory:");
f->open(QIODevice::WriteOnly);
f->write(decrypted);
f->close();
QSqlDatabase db;
db = QSqlDatabase::addDatabase("QSQLITE");
db.setDatabaseName(":memory:");
db.open();
QSqlQuery query(db);
query.exec("SELECT * FROM data");
while(query.next())
{
qDebug() << query.value(0).toString();
}
And got this error:
QIODevice::write (QFile, ":memory:"): device not open
How can I do that?
f->open()is ignored and the error atf->write()is expected.:memory:is a sqlite concept not something you can use with QFileQFile(":memory:");is completely inappropriate. As written above, it's a sqlite concept, not a real path. The result of the above would be to try to open a physical file named ":memory:" in the current working dir. Even assuming that it would work (and it won't at least on Windows, for which the colon is an illegal character for file or directory names), then it would obviously fail your requirement of a memory object. Also, as thesetDatabaseName()docs explain, when using:memory:with the SQLite driver it will "create a temporary database", so it's inappropriate anyways.sqlite3_deserializecan create a SQLite connection on an in-memory blob of data (usually obtained from a previous call tosqlite3_serialize. Here's an example of diggingsqlite3*handle out ofQSqlDatabaseobject.