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

QSQLITE option to use extended result codes

    XMLWordPrintable

Details

    • Suggestion
    • Resolution: Fixed
    • Not Evaluated
    • 6.1.0 Beta 1
    • 5.9, 5.10, 5.11
    • SQL Support
    • None
    • All
    • ce90248882b73b4b816a8550710279e3e55ab64c

    Description

      When the user tries to add a entity twice, the application should be able to tell him the error precisely.

      Technically, a UNIQUE constraint is used in a SQLite database. When executing a insert query, using QSqlQuery, and it fails, I use query.lastError().nativeErrorCode().  (defined in QSqlError).

      The problem is that it returns the code 19, which is SQLITE_CONSTRAINT, defined in sqlite3.h.

      This error is to generic (it could be foreign key constraint error, etc..).

      SQLite provides the concept of extended result codes.

      For the above case , SQLITE_CONSTRAINT_UNIQUE (2067) should be returned.

      As described in the SQLite documentation, returning extended result codes by default is disabled for historical compatibility reason.

      SQLite provides a function to return extended reult codes by default.

      My suggestion is to add connection option ( see QSqlDatabase::setConnectOptions() ): QSQLITE_USE_EXTENDED_RESULT_CODES .

       In QSQLiteDriver::open() method, sqlite3_extended_result_codes(d->access, 1) could be called if this option is set. I attached the modified qsql_sqlite.cpp .

       

      Attachments

        Activity

          People

            mabrand Mark Brand
            scandyna Philippe Steinmann
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: