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

sqlStatement() wrongly ignores columns where value is invalid

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • P2: Important
    • 4.8.0
    • 4.7.0
    • SQL Support
    • None
    • Probably all.
    • 0f15ab4e750690bdb2b649332d5c3276bf24c440

    Description

      When generating UPDATE and INSERT statements, QSqlDriver::sqlStatement omits fields where the QVariant value is invalid, i.e., has type QVariant::Invalid.

      This seems wrong for the following reasons:

      • The documented behavior is that the "generated" property of QSqlField determines whether to include the field in the generated statement.
      • It is not necessary or even reasonable to assume that values in the record passed to sqlStatement() will contain valid values.
      • A plausible source for a record is QSqlDatabase::record ( const QString & tablename ). Such records contains invalid values.
      • This behavior is especially troublesome when using parametrized queries. The programmer is likely to construct value lists that match the fields in the record, but such value lists might not match the generated statement, causing errors at runtime.

      For parameterized queries, the value has no consequence anyway since a placeholder is used. For non-parameterized queries, invalid values should probably be rendered as NULL.

      The attached code illustrates this behavior.

      Proposed fix here:
      http://qt.gitorious.org/qt/qt/merge_requests/789

      Attachments

        1. main.cpp
          1 kB
          Mark Brand
        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            mgoddard Michael Goddard (closed Nokia identity) (Inactive)
            mabrand Mark Brand
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes