I'm using Qt5 with an QSqlDatabase with QSQLITE. I initialize the Database with
db.setDatabaseName("test.db");
if (!db.open()) { ...}
db = QSqlDatabase::addDatabase("QSQLITE");
db.setDatabaseName("test.db");
if (!db.open()) { ...}
To copy to clipboard, switch view to plain text mode
Two instances of the program or running on the same machine therefore both or using the same test.db database file. The initialization of the database works fine, but when executing
bool DataStorageHandler
::executeStmt(QString stmt
) { qry.prepare(stmt);
if (!qry.exec()) {
qDebug() << stmt;
this->dbError = qry.lastError().text();
return false;
} else
return true;
}
bool DataStorageHandler::executeStmt(QString stmt) {
QSqlQuery qry(this->db);
qry.prepare(stmt);
if (!qry.exec()) {
qDebug() << stmt;
this->dbError = qry.lastError().text();
return false;
} else
return true;
}
To copy to clipboard, switch view to plain text mode
Both instances at this point are executing an INSERT-Stmt but one of them gets an error
database is locked Unable to fetch row
I don't understand why? Shouldn't sqlite handle different accesses to the DB?
Bookmarks