Results 1 to 3 of 3

Thread: Can you retrieve QSqlQuery.LastError after QSqlQuery.Finish?

  1. #1
    Join Date
    Dec 2011
    Posts
    36
    Thanks
    14
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Can you retrieve QSqlQuery.LastError after QSqlQuery.Finish?

    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.

  2. #2
    Join Date
    Mar 2009
    Location
    Brisbane, Australia
    Posts
    7,729
    Thanks
    13
    Thanked 1,610 Times in 1,537 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Wiki edits
    17

    Default Re: Can you retrieve QSqlQuery.LastError after QSqlQuery.Finish?

    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.
    Qt Code:
    1. void QSqlQuery::finish()
    2. {
    3. if (isActive()) {
    4. d->sqlResult->setLastError(QSqlError());
    5. ...
    To copy to clipboard, switch view to plain text mode 

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

  3. The following user says thank you to ChrisW67 for this useful post:

    m3rlin (9th April 2013)

  4. #3
    Join Date
    Dec 2011
    Posts
    36
    Thanks
    14
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Can you retrieve QSqlQuery.LastError after QSqlQuery.Finish?

    Quote Originally Posted by ChrisW67 View Post
    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.

Similar Threads

  1. QSqlQuery
    By rajko in forum Newbie
    Replies: 7
    Last Post: 24th May 2012, 22:26
  2. Replies: 1
    Last Post: 18th July 2011, 13:12
  3. Using QSqlQuery
    By darkman_dev in forum Newbie
    Replies: 2
    Last Post: 4th February 2011, 22:40
  4. Replies: 3
    Last Post: 25th August 2009, 14:03
  5. Qt 4.5.1 / MySQL 5.1, QSqlQuery::lastError() 1295
    By wdezell in forum Qt Programming
    Replies: 1
    Last Post: 21st July 2009, 16:36

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.