Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct


    Qt World Summit: Early-Bird Tickets

    Unsolved QSqlRelationalTableModel fail update

    General and Desktop
    1
    2
    251
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • Jukov
      Jukov last edited by

      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?

      1 Reply Last reply Reply Quote 0
      • Jukov
        Jukov last edited by

        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

        1 Reply Last reply Reply Quote 0
        • First post
          Last post