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

QSqlTableModel serious bug when preparing statement

    XMLWordPrintable

Details

    • Bug
    • Resolution: Duplicate
    • P2: Important
    • 4.7.4
    • 4.6.3
    • SQL Support
    • None
    • kubuntu 10.04
      g++ 4.2.4
      PostgreSQL 8.4

    Description

      The bug occurs in QSqlTableModelPrivate::exec().
      When the prepared statement contains a NULL value for some field, for example :

         DELETE FROM aTable WHERE "id" = ? AND "field1" = ? AND "field2" IS NULL AND "field3" = ?
      

      Then this leads to a SQL error like :

         ERROR: wrong number of parameters for prepared statement "qpsqlpstmt_1"
         DETAIL: Expected 3 parameters but got 4
      

      The problem is located in qsqltablemodel.cpp, line 204 :

      204  if (rec.isGenerated(i) && rec.value(i).type() != QVariant::Invalid)
      205    editQuery.addBindValue(rec.value(i));
      

      "rec.value( i )" can be a valid NULL QVariant (like QVariant(QVariant::Int)), and in this case line 205 is executed (which should not).

      Attachments

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

        Activity

          People

            charles Charles Yin (closed Nokia identity) (Inactive)
            cerf Hugues Delorme
            Votes:
            2 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes