Results 1 to 5 of 5

Thread: How to get sqlite error message RAISE by trigger

  1. #1
    Join Date
    Aug 2008
    Posts
    70
    Thanks
    5
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default How to get sqlite error message RAISE by trigger

    Hi,

    I have a sqlite database containing trigger to manage constraints.
    (see attached file)

    If I try to violate a constraint with sqlite3, the right error message is returned:
    Qt Code:
    1. sqlite> delete from unit;
    2. SQL error: delete on table unit violates foreign key constraint fkd_unit_unit_rc_unit_id_id
    To copy to clipboard, switch view to plain text mode 


    But, if I try to violate a constraint with QT API (QSqlQuery), this error message is returned by QSqlError::lastError():
    Qt Code:
    1. constraint failed Impossible d'extraire la ligne
    To copy to clipboard, switch view to plain text mode 


    Do you know how to do to retrieve the right error message with QT API ?

    In advance, thank you.
    Attached Files Attached Files

  2. #2
    Join Date
    Mar 2008
    Posts
    141
    Thanks
    10
    Thanked 9 Times in 9 Posts

    Default Re: How to get sqlite error message RAISE by trigger

    Hi,

    what about

    Qt Code:
    1. QString QSqlError::driverText () const
    To copy to clipboard, switch view to plain text mode 

    or maybe you can use

    Qt Code:
    1. int QSqlError::number () const
    To copy to clipboard, switch view to plain text mode 

    and get the sqlite error description from http://www.sqlite.org/c3ref/errcode.html

  3. #3
    Join Date
    Aug 2008
    Posts
    70
    Thanks
    5
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: How to get sqlite error message RAISE by trigger

    Hi Janus,

    In fact, I am using QString QSqlError::text ().

    In documentation, we can read:
    This is a convenience function that returns databaseText() and driverText() concatenated into a single string.
    So, driverText() is not the solution.

    I don't know how to get the message RAISE by the trigger.

    An other idea ?

  4. #4
    Join Date
    Mar 2008
    Posts
    141
    Thanks
    10
    Thanked 9 Times in 9 Posts

    Default Re: How to get sqlite error message RAISE by trigger

    Hi,

    maybe use the sqlite API directly? e.g. const char *sqlite3_errmsg(sqlite3*);
    (http://www.sqlite.org/capi3ref.html#sqlite3_errcode)

    from QSqlDriver:

    Qt Code:
    1. This example retrieves the handle for a connection to sqlite:
    2.  
    3. QSqlDatabase db = ...;
    4. QVariant v = db.driver()->handle();
    5. if (v.isValid() && v.typeName() == "sqlite3*") {
    6. // v.data() returns a pointer to the handle
    7. sqlite3 *handle = *static_cast<sqlite3 **>(v.data());
    8. if (handle != 0) { // check that it is not NULL
    9. ...
    10. }
    11. }
    To copy to clipboard, switch view to plain text mode 


    ... i used that for enabeling extension loading, but I can't find the code right now

    EDit:
    sry, i gave it a try ...guess my C/C++ knowledge is by far not good enought to use something like this. But using the handle to call a c sqlite function did work afair
    Last edited by janus; 17th November 2008 at 21:19.

  5. #5
    Join Date
    Aug 2008
    Posts
    70
    Thanks
    5
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default [RESOLVED] How to get sqlite error message RAISE by trigger

    Thank you for the solution !

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.