Re: Abort QSqlQuery::exec()
It's not possible. You would have to terminate the thread execution since QSqlQuery::exec() is a blocking function. However, aborting a thread is not recommended, as the documentation states:
Quote:
Warning: This function is dangerous and its use is discouraged. The thread can be terminate at any point in its code path. Threads can be terminated while modifying data. There is no chance for the thread to cleanup after itself, unlock any held mutexes, etc. In short, use this function only if absolutely necessary.
In the end, if you want to be able to safely abort a query, the only suitable way I can think of is creating a child process that performs the queries and killing it when you need to abort the query.
However, if you're not going to abort the query very often, you may try with terminate(), keeping in mind it's risky and it can produce crashes, memory leaks and so on. I'm using terminate() in my application and it's working fine but I normally don't need to call it, it's a last-resort.
Re: Abort QSqlQuery::exec()
Quote:
Originally Posted by
victor.fernandez
However, aborting a thread is not recommended, as the documentation states:
I read about terminating a thread and it's not something I'm going to consider as long as I'm sure it's safe to do (and I probably won't be with QSqlQuery::exec()).
Quote:
Originally Posted by
victor.fernandez
However, if you're not going to abort the query very often, you may try with terminate()
Unfortunately I'm going to kill them fairly often.
Quote:
Originally Posted by
victor.fernandez
keeping in mind it's risky and it can produce crashes, memory leaks and so on. I'm using terminate() in my application and it's working fine but I normally don't need to call it, it's a last-resort.
For me it's not even a last resort. For me it's unacceptable to write application in a way it allows situations in which application may crash (in theory memory leaks lead to using up all memory, so it's also a thing leading to crash).
Re: Abort QSqlQuery::exec()
you can terminate the thread, but QSqlQuery .exec continue runing.
Re: Abort QSqlQuery::exec()
Does the database you are working with support paging?
If yes you could probably execute your query in smaller pieces.
Cheers,
_
Re: Abort QSqlQuery::exec()
Don't forget to thoroughly investigate why your single query is taking minutes, where that time is being spent, and redesign or adapt the query and database to perform better. Better joins, better indexes, temporary tables are all candidates you investigate.