Results 1 to 5 of 5

Thread: SQL exception handling

  1. #1
    Join Date
    Jan 2017
    Posts
    8
    Qt products
    Qt5
    Platforms
    Windows

    Default SQL exception handling

    Hello

    I use QqSqlTableModel and tableView together.
    How can i detect SQL server exceptions, errors ? (for example : Key violation, foreign key error etc....)

    thnak you Attila

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts

    Default Re: SQL exception handling

    See QSqlTableModel::lastError() on how to get an SQL error object.

    Cheers,
    _

  3. #3
    Join Date
    Jan 2017
    Posts
    8
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: SQL exception handling

    Thank you anda_skoa

    but i edit the recod in a tableview manually
    How can i get a message about the record is saved or not (because of sql error)

    thank you Attila

  4. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,416
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows
    Thanks
    37
    Thanked 1,544 Times in 1,494 Posts

    Default Re: SQL exception handling

    If you run through the model, then it has the error. That's why it is called "lastError".

    If you run a QSqlQuery manually, then it has its own error object.

    Cheers,
    _

  5. #5
    Join Date
    Jan 2017
    Posts
    8
    Qt products
    Qt5
    Platforms
    Windows

    Default Re: SQL exception handling

    Thank you , Sir

    Ok. It's working. I have understood.

    thank you again

Similar Threads

  1. Exception from moveToThread
    By Phlucious in forum Qt Programming
    Replies: 12
    Last Post: 8th March 2012, 00:12
  2. Exception handling in external library - good or bad idea
    By kornicameister in forum Qt Programming
    Replies: 0
    Last Post: 20th February 2012, 14:25
  3. exception
    By AnithaRagupathy in forum Qt Programming
    Replies: 1
    Last Post: 14th November 2007, 09:59
  4. Exception handling in Qt 4.2.2
    By vishal.chauhan in forum Qt Programming
    Replies: 1
    Last Post: 27th February 2007, 09:47
  5. Qt's Exception Handling
    By bruce1007 in forum Qt Programming
    Replies: 2
    Last Post: 13th June 2006, 09:30

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
  •  
Qt is a trademark of The Qt Company.