Driver not loaded QSQlite when I give connection name
-
Hello,
When I use QSQlite with
databaseManager::databaseManager() { db = QSqlDatabase::addDatabase("QSQLITE"); db.setDatabaseName(db_URL); } void databaseManager::dbinitmagUrl() { { db.open(); QSqlQuery query(db); if(!query.exec("CREATE TABLE IF NOT EXISTS dbMagasin_log (ligne_id INTEGER PRIMARY KEY AUTOINCREMENT, url TEXT)")) { qDebug() << "query return error at line:"<<QString::number(__LINE__)<<query.lastError().text(); } } QSqlDatabase::removeDatabase("QSQLITE"); }
My app is working.
But when I try to use connection name, I receive error
QSqlDatabasePrivate::removeDatabase: connection 'test' is still in use, all queries will cease to work.
QSqlQuery::exec: database not open
"query return null at line:561" QSqlError("", "Driver not loaded", "Driver not loaded")databaseManager::databaseManager() { db = QSqlDatabase::addDatabase("QSQLITE", "test"); db.setDatabaseName(db_URL); } void databaseManager::dbinitmagUrl() { { db.open(); QSqlQuery query(QSqlDatabase::database("test")); if(!query.exec("CREATE TABLE IF NOT EXISTS dbMagasin_log (ligne_id INTEGER PRIMARY KEY AUTOINCREMENT, url TEXT)")) { qDebug() << "query return error at line:"<<QString::number(__LINE__)<<query.lastError().text(); } } QSqlDatabase::removeDatabase("test"); }
Could you help me?
Thanks a lot
-
@philxxx609 said in Driver not loaded QSQlite when I give connection name:
db = QSqlDatabase::addDatabase("QSQLITE", "test");
db.setDatabaseName(db_URL);Do NOT store QSqlDatabase instances in variables!
This is explained in the documentation. -
I just saw that, thank you.
Do you know the best practice to use sqlite in multi users connection?
-
@philxxx609 said in Driver not loaded QSQlite when I give connection name:
Do you know the best practice to use sqlite in multi users connection?
Not sure what you mean with "best practice".
SQlite supports parallel accesses, but if one process is writing the DB will be locked until writing has finished. -
@philxxx609 I'm not sure your app will block. Never used SQLitein such configuration. Try it out and see what happens, maybe your query will fail as long as the database is blocken, in this case your app will not be blocked.
-
@philxxx609 Then SQLite is not the right database for your use case