PDA

View Full Version : Can you retrieve QSqlQuery.LastError after QSqlQuery.Finish?



m3rlin
9th April 2013, 09:24
Quick question since documentation is not very clear about this:

When freeing up recourses by calling QSqlQuery Finish, does it clear the QSqlQuery lastError? I know it will keep bound values according to the Class Reference, but I can't find or test yet if it keeps the QSqlQuery lasterror?
Thx in advance.

ChrisW67
9th April 2013, 09:55
You could spend five minutes writing a quick test or reading the Qt source code to see that it does. Alternatively, you could just assume that it does not and cache lastError() before you do.


void QSqlQuery::finish()
{
if (isActive()) {
d->sqlResult->setLastError(QSqlError());
...


The docs are quite clear that you probably do not need to be calling finish() anyway.

m3rlin
9th April 2013, 10:15
You could spend five minutes writing a quick test or reading the Qt source code to see that it does. Alternatively, you could just assume that it does not and cache lastError() before you do.
The docs are quite clear that you probably do not need to be calling finish() anyway.

I did read the source, and the I did read about not needing to call finish UNLESS you want to free up resources. I do currently cache the lastError() before calling finish, but in my search for chipping away extra extra extra safety code I needed to be absolutely sure. And although the source is very obvious about it... I'd better ask than having to apologize later. And due DB maintenance I currently don't have access to the DB-es so I couldn't test it myself.

Thx.