Cerberus
10th October 2015, 12:11
I'm using Qt5 with an QSqlDatabase with QSQLITE. I initialize the Database with
db = QSqlDatabase::addDatabase("QSQLITE");
db.setDatabaseName("test.db");
if (!db.open()) { ...}
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) {
QSqlQuery qry(this->db);
qry.prepare(stmt);
if (!qry.exec()) {
qDebug() << stmt;
this->dbError = qry.lastError().text();
return false;
} else
return true;
}
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?
db = QSqlDatabase::addDatabase("QSQLITE");
db.setDatabaseName("test.db");
if (!db.open()) { ...}
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) {
QSqlQuery qry(this->db);
qry.prepare(stmt);
if (!qry.exec()) {
qDebug() << stmt;
this->dbError = qry.lastError().text();
return false;
} else
return true;
}
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?