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

QSqlRelationalTableModel filter bug

    XMLWordPrintable

    Details

    • Type: Bug
    • Status: Reported
    • Priority: P4: Low
    • Resolution: Unresolved
    • Affects Version/s: 5.2.1
    • Fix Version/s: None
    • Component/s: SQL Support
    • Labels:
      None
    • Environment:
      Os: Win7, Qt 5.2.1, Mingw_32, QtCreator 3.3.0

      Description

      Given:
      Postgresql DB with tables as follows
      bcrm_clients

      {id, name, client_type_id, business_type_id, manager_id,...}

      bcrm_ref_client_type {id, name));
      bcrm_ref_client_business_type

      {id, name}
      bcrm_ref_managers {id, name}
      Model Code
      QSqlRelationalTableModel *model = new QSqlRelationalTableModel();
          model->setTable("bcrm_clients");
          model->setRelation(2, QSqlRelation("bcrm_ref_client_type", "id", "name"));
          model->setRelation(3, QSqlRelation("bcrm_ref_client_business_type", "id", "name"));
          model->setRelation(4, QSqlRelation("bcrm_ref_managers", "id", "name"));
          model->setJoinMode(QSqlRelationalTableModel::LeftJoin);
          model->setFilter(QString("bcrm_clients.\"id\" = %1").arg(currentId));
      

      Widget containing QDataWidgetMapper with OnManualSubmit flag.

      Submit Code
      //    m_Mapper->submit();
      //    saveAct->setEnabled(false);
      //    setWindowModified(false);
          if(m_Mapper->submit()){
      //
      //
          } else {
              qDebug() << m_Model->lastError();
          }
      

      Everything works like a charm except, when introducing change for any field in a widget, and then call submit function (see above), it returns false, though chages are submited to db. Postgresql gives me following error:

      error code
      column reference "id" is ambiguous at character 663
      STATEMENT:  SELECT bcrm_clients."id",bcrm_clients."name",relTblAl_2.name AS bcrm_ref_client_type_name_4,relTblAl_3.name AS bcrm_ref_client_business_type_name_3,relTblAl_4.name AS bcrm_ref_managers_name_2,bcrm_clients."phone",bcrm_clients."website",bcrm_clients."base_discount",bcrm_clients."additional_discount",bcrm_clients."current_contract",bcrm_clients."is_contract_signed" FROM bcrm_clients LEFT JOIN bcrm_ref_client_type relTblAl_2 ON bcrm_clients."client_type_id"=relTblAl_2.id LEFT JOIN bcrm_ref_client_business_type relTblAl_3 ON bcrm_clients."business_type_id"=relTblAl_3.id LEFT JOIN bcrm_ref_managers relTblAl_4 ON bcrm_clients."manager_id"=relTblAl_4.id WHERE ("id" = someid)
      

      As can be seen Filter portion slightly changed from what i had initially.
      So i started to dig through qt sql models code and found this line that is causing my filter to go bad

      qsqlrelational code
          const QString where = Sql::where(Sql::et(Sql::paren(conditions), Sql::paren(filter()))); 
      

      Line 621 qsqlrelationaltablemodel.cpp

      So apparently during updateRowInTable() sqltablemodel changes filter to simple id = something. Later on we try to select from db and in line 621 call sqltablemodel's filter(), and its still holds "simple id = something"

        Attachments

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

          Activity

            People

            Assignee:
            mabrand Mark Brand
            Reporter:
            Stillsly Alexei Ermakov
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

              Dates

              Created:
              Updated:

                Gerrit Reviews

                There are no open Gerrit changes