Too much query executed with QSqlQuery cause fatal signal if executed in different thread
-
If I execute a large number of query stored in qstringlist with qsqlquery in new thread, the application stop execution with this message:
" F libc : Fatal signal 7 (SIGBUS), code 1, fault addr 0x1e in tid 855 (qtMainLoopThrea)"
while execution of queries on database (after about 300 queries in release mode and after about 700 queries in debug mode).
The database is qsqlite and there is just one connection opened.
Please help me! -
Hi,
AFAIR, the correct way to do that is to open a new connection to the database per thread. On a side note, are you really creating 300 threads in parallel to execute queries ? A QThreadPool might be of interest in this case.
-
At no point did I say the query was the problem. What I wrote is that you should open one connection to the database per thread and not use the same connection from all the threads.
-
-
Can you show how you do that ?
Out of curiosity, why use SQLite for what seems to be a pretty intensive database use ? Something like PostgreSQL might be a better fit.
-
baseThreadStart(){
if (thPool == nullptr){
thPool = new QThreadPool(this);
thPool->setExpiryTimeout(-1);
}
else {
thPool->clear();
}thPool->start(exQry);
}QRunnableDerivedObject::run(){
QSqlDatabase db = QSqlDatabase::database(connName);
if (!db.isValid()){
db = QSqlDatabase::addDatabase(tipoDb,connName);
db.setDatabaseName(dbFullPath);
}if (!db.open()){ emit errore("Database non accessibile\n" + db.lastError().text()); db.removeDatabase(connName); return; }else { if (!queryList.empty()){ t = queryList.count(); emit totaleOp(c + 1, t); ferma = false; for (int i = c; i < t; i++) { if (ferma) break; QString qrStr = queryList.at(i); if (!qrStr.isEmpty()){ QSqlQuery qr(qrStr,db);
#ifdef QT_DEBUG
qDebug() << QString::number(i + 1) + ": " + qrStr;
#endifif (!qr.exec(qrStr)) { emit errore("Impossibile completare un'operazione sul database: \n" + db.databaseName() + "\n" + "Errore: " + qr.lastError().text() + "\n" + qrStr); emit log(qrStr); } } emit totaleOp(i + 1,t); } }
....sorry for delay but I need to wait 10 minutes between reply
-
@cmra said in Too much query executed with QSqlQuery cause fatal signal if executed in different thread:
connName
Where is it defined ? What does it contain ?
-
The processEvents() calls does not change nothing (I call it at line number 300 and the error happen at line 315 in release build). The error happen again.
connName is a global QString variable defined in the QRunnableDerivedObject and it's value is "async_conn", but this connection name is used only with one QSqlDatabase at start of importing process, no more. -
So there's your problem: you are creating connections with the exact same name in all of your threads. You should make the name unique per thread. For example add the thread id to the connection string.
-
No it doesn't...because as I explained before I have just one thread and so just one connection.. I create only one thread fot importing data and no other. The connections in the main app don't use thread to exec query and they have different names.
I don't beleave that QThreadPool create more than one thread itself. -
To be sure to understand you correctly, you are trying to execute 33000 queries on an Android phone ? What kind of device is that ?
-
Yes it is right....I tried on Samsung S6 and Samsung j6. But I already execute with success all the queries in the past, but now I can't find what wrong...if depend by an update of android sdk or ndk or I made a mistake in some place (the code is so simple that I exclude that).
So I ask for help to you because may be some errors that I can't see.