Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-40586

QSqlError offers no access to SQLSTATE

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • P3: Somewhat important
    • None
    • 4.8.6
    • SQL Support
    • n/a

    Description

      (Update: this is fixed in qt5 per last comment, and just needs a docs update to make that clear)


      There's a serious API issue with QSqlError. It only offers users access to error message text, which is locale and version specific.

      It does not expose the SQLSTATE that's the standard and portable mechanism for identifying and classifying errors.

      Without this it is not possible to write reliable QtSQL applications with correct error handling. Any existing applications will break if the database server is on an unexpected locale, or they'll be unable to tell the difference between an error that should cause a transaction re-try (e.g. deadlock, serialization failure), an error that indicates a connection problem, and an error that a retry won't help with like a missing column or data type cast error.

      Java's SQLException should be examined as a model. http://docs.oracle.com/javase/7/docs/api/java/sql/SQLException.html

      Individual drivers should throw their own subclasses of QSqlError that provide additional driver-specific information. For example, look at PgJDBC's subclass of the Java SQLException, which exposes the PostgreSQL "detail" and "hint" fields, line number information, position in the SQL statement text, etc.

      http://jdbc.postgresql.org/development/privateapi/org/postgresql/util/PSQLException.html

      This report was prompted by this user complaint: http://stackoverflow.com/q/25130212/398670 and my surprise, upon investigating, at discovering that Qt doesn't expose basic SQL diagnostic information.

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            mabrand Mark Brand
            craig2ndq Craig Ringer
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes