Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

QSqlRelationalTableModel fail update



  • My db 0_1528996807029_Снимок экрана от 2018-06-13 18-55-19.jpg
    personnelModel = new QSqlRelationalTableModel(this,db);
    personnelModel->setTable("Personnel");
    currentModel = operationModel;
    currentModel->setRelation(currentModel->fieldIndex("Articul_idArticul"),QSqlRelation("Articul", "idArticul", "Number"));
    // qDebug()<<currentModel->lastError()<<currentModel->query().lastQuery();
    currentModel->setEditStrategy(QSqlRelationalTableModel::OnFieldChange);
    currentModel->select();
    ui->tableView->setModel(currentModel);The data is correctly displayed.
    Qt does not issue errors.
    After selecting in the combobox, the value is not updated, I looked up the database logs and saw it 0_1528996822915_Снимок экранаКонсоль.jpg
    Why does "is null" appear?



  • I found this code in qsqldriver.cpp.

    case WhereStatement:
       {
           const QString tableNamePrefix = tableName.isEmpty()
               ? QString()
               : prepareIdentifier(tableName, QSqlDriver::TableName, this) + QLatin1Char('.');
           for (int i = 0; i < rec.count(); ++i) {
               if (!rec.isGenerated(i))
                   continue;
               s.append(s.isEmpty() ? QLatin1String("WHERE ") : QLatin1String(" AND "));
               s.append(tableNamePrefix);
               s.append(prepareIdentifier(rec.fieldName(i), QSqlDriver::FieldName, this));
               if (rec.isNull(i))
                   s.append(QLatin1String(" IS NULL"));
               else if (preparedStatement)
                   s.append(QLatin1String(" = ?"));
               else
                   s.append(QLatin1String(" = ")).append(formatValue(rec.field(i)));
           }
           break;
       }
    

    "IS NULL" appears from the fact that QSqlRecord &rec is null, but when i get record from model it returned normal record


Log in to reply