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

QSqlTableModel record (after insertRow) marks fields as non generated, losing their value

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Closed
    • Priority: P2: Important
    • Resolution: Done
    • Affects Version/s: 5.2.1, 5.3.0
    • Fix Version/s: 5.11.1
    • Component/s: SQL Support
    • Labels:
      None
    • Commits:
      4deea4b905ea1ad32fde317f8556a5c8cdd775cd

      Description

      Code like this (with a MYSQL backend) worked fine with Qt 4.8:

      m_supportTableModel = new QSqlTableModel(this);
      m_supportTableModel->setTable("...");
      m_supportTableModel->setEditStrategy(QSqlTableModel::OnManualSubmit);
      m_supportTableModel->insertRow(0);
      QSqlRecord record = m_supportTableModel->record(0);
      qDebug() << record; // all fields had generated: yes
      record.setValue("CODE_SUPPORT", m_codeSupport);
      m_supportTableModel->setRecord(0, record);
      m_supportTableModel->submitAll(); // returned true

      With Qt 5.2, all fields have "generated: no", and therefore the value for CODE_SUPPORT isn't stored (and the submitAll fails since this is a required value).

      Since I use QDataWidgetMapper for the other fields, they go through QSqlTableModel::setData which calls ModifiedRow::setValue which sets generated to true. Why doesn't QSqlRecord::setValue do the same, for the case of values set by the application?

      The documentation for QSqlTableModel::setRecord says "remember to set generated to false if the db is meant to supply the value"... well, I'm supplying all the values, so I didn't expect to have to set it to true, it sounds like it's the default – and it was, in Qt 4.8.

        Attachments

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

          Activity

            People

            Assignee:
            andysh Andy Shaw
            Reporter:
            dfaure_kdab David Faure
            Votes:
            2 Vote for this issue
            Watchers:
            7 Start watching this issue

              Dates

              Created:
              Updated:
              Resolved:

                Gerrit Reviews

                There are no open Gerrit changes