Announcement

Collapse
No announcement yet.
X
  • Filter
  • Time
Clear All
new posts

    [bug] combineCriteria gives incorrect result

    SmartClient Version: v8.2p_2012-10-02/PowerEdition Deployment (built 2012-10-02)
    and
    SmartClient Version: v8.3p_2013-01-04/PowerEdition Deployment (built 2013-01-04)
    and
    SmartClient Version: v8.3p_2013-01-13/PowerEdition Deployment (built 2013-01-13)

    Chrome 24.0.1312.52

    I have a list grid bound to a datasource which has several foreign keys (to differente tables):
    Code:
    <DataSource ID="JPC_CONTRATTI"
                tableName="JPC_CONTRATTI"
                schema="DBSALES"
                dbName="dbJpcEP"
                serverType="sql"
                dropExtraFields="false"
            >
        <fields>
            <field sqlType="decimal" primaryKey="true" name="ID_REC" type="sequence" hidden="true">
                <sequenceName>SEQUENCE_ID_REC</sequenceName>
            </field>
            <field foreignKey="JPC_STAGIONI.ID_REC" sqlType="decimal" sqlLength="0" name="ID_STAGIONI_FK" type="integer"
                   optionDataSource="JPC_STAGIONI" valueField="ID_REC" displayField="DESCRIZIONE">
            </field>
            <field name="STAGIONE" type="text" tableName="JPC_STAGIONI" nativeName="DESCRIZIONE"/>
            <field sqlType="decimal" sqlLength="0" name="CONTRATTO_NUM" type="integer">
            </field>
            <field foreignKey="JPC_ANAGRAFICA_CLIENTI.ID_REC" sqlType="decimal" sqlLength="0" type="integer" name="ID_ANAGRAFICA_CLIENTI_FK" displayField="SOGGETTO_DESC">
            </field>
            <field name="TIPO_SOGGETTO" type="text" tableName="JPC_TIPI_SOGGETTO" nativeName="DESCRIZIONE">
            </field>
            <field name="SOGGETTO_DESC" type="text"
                   customSelectExpression="decode(JPC_TIPI_SOGGETTO.CODICE, 'AZ', JPC_ANAGRAFICA_CLIENTI.SOGGETTO_DESC, JPC_ANAGRAFICA_CLIENTI.COGNOME || ' ' || JPC_ANAGRAFICA_CLIENTI.NOME)"/>
            <field foreignKey="JPC_STATI_CONTRATTO.ID_REC" sqlType="decimal" sqlLength="0" type="integer"
                   name="ID_STATO_CONTRATTO_FK" displayField="CODICE">
            </field>
            <field foreignKey="JPC_CONTRATTI.ID_REC" sqlType="decimal" sqlLength="0" type="integer" name="ID_CONTRATTO_PRECEDENTE_FK"></field>
            <field name="CONTRATTO_NUM_PRECEDENTE" type="integer" customSelectExpression="(select a.CONTRATTO_NUM from JPC_CONTRATTI a where JPC_CONTRATTI.ID_CONTRATTO_PRECEDENTE_FK = a.ID_REC)">
            </field>
            <field sqlType="decimal" name="ID_NOTE_INTERNE_FK" type="integer" foreignKey="JPC_NOTE.ID_REC">
            </field>
        </fields>
        <operationBindings>
            <operationBinding operationType="fetch">
                        <tableClause>$defaultTableClause, JPC_CONTRATTI_RIGHE, JPC_VOCI_DI_LISTINO, JPC_STATI_CONTRATTO, JPC_STAGIONI, JPC_ANAGRAFICA_CLIENTI, JPC_TIPI_SOGGETTO</tableClause>
                <whereClause>
                    $defaultWhereClause
                    and JPC_ANAGRAFICA_CLIENTI.ID_REC = JPC_CONTRATTI.ID_ANAGRAFICA_CLIENTI_FK
                    and JPC_ANAGRAFICA_CLIENTI.ID_TIPI_SOGGETTO_FK = JPC_TIPI_SOGGETTO.ID_REC
                    and JPC_CONTRATTI_RIGHE.ID_VOCE_LISTINO_PER_SCONTO_FK = JPC_VOCI_DI_LISTINO.ID_REC(+)
                    and JPC_CONTRATTI.ID_REC = JPC_CONTRATTI_RIGHE.ID_CONTRATTI_FK(+)
                    and JPC_CONTRATTI.ID_STATO_CONTRATTO_FK = JPC_STATI_CONTRATTO.ID_REC(+)
                    and JPC_CONTRATTI.ID_STAGIONI_FK = JPC_STAGIONI.ID_REC(+)
                </whereClause>
            </operationBinding>
        </operationBindings>
    </DataSource>
    I have a form to select and filter the grid on one of those foreign keys:
    Code:
    isc.DynamicForm.create({
        ID:"sceltaStagioneCorrenteForm",
        getStagioneCorrente:function () {
            return this.getValue('ID_STAGIONI_FK') || this.getStagioneCorrenteOffline();
        },
        setStagioneCorrente:function (idStagione) {
            this.setValue('ID_STAGIONI_FK', idStagione);
        },
        fetchStagioneCorrente:function (callback, dsRequestProperties) {
            var advancedCriteria = {
                _constructor:"AdvancedCriteria",
                operator:"and",
                criteria:[
                    { fieldName:"DATA_INIZIO", operator:"lessOrEqual", value:new Date() },
                    { fieldName:"DATA_FINE", operator:"greaterOrEqual", value:new Date() }
                ]
            };
            JPC_STAGIONI.fetchData(
                advancedCriteria,
                callback,
                dsRequestProperties
            );
        },
        aggiornaStagioneCorrenteOffline:function (idStagioneFk) {
            isc.Offline.put('jpcep.stagioneCorrenteId', idStagioneFk);
        },
        dataFetchMode:"basic",
        getStagioneCorrenteOffline:function () {
            return isc.eval(isc.Offline.get('jpcep.stagioneCorrenteId'));
        },
        items:[
            {
                name:"ID_STAGIONI_FK", type:"select", optionDataSource:"JPC_STAGIONI",
                optionCriteria:{fieldName:"DESCRIZIONE", operator:"notEqual", value:'2011/2012'},
                displayField:"DESCRIZIONE", valueField:"ID_REC", width:100,
                defaultDynamicValue:function (item, form, values) {
                    var idStagioneCorrente = form.getStagioneCorrenteOffline();
                    if (!idStagioneCorrente) {
                        form.fetchStagioneCorrente(
                            function (dsResponse, data, dsRequest) {
                                if (data && data[0]) {
                                    dsRequest.form.aggiornaStagioneCorrenteOffline(data[0].ID_REC);
                                    dsRequest.form.setStagioneCorrente(data[0].ID_REC);
                                }
                            },
                            {form:form}
                        );
                    }
                    return idStagioneCorrente;
                },
                title:i18nMessages.gestioneContratti + ' - ' + i18nMessages.sceltaStagione, titleStyle:"formTitleInSectionControls",
                changed:function (form, item, value) {
                    form.aggiornaStagioneCorrenteOffline(value);
                }
            }
        ]
    });
    the selection is observed by a grid which is bounded to the above datasource. On execution of observed method the 'updateFilterStagioneCorrente' gets called (this is modelled after the click method of the orderItemCriteriaForm in the #dynamicReporting sample)
    Code:
    isc.ListGrid.create({
        ID:"elencoContrattiGrid",
        dataSource:"JPC_CONTRATTI",
        height:"60%",
        selectionType:"single",
        initialSort:[
            {property:"CONTRATTO_NUM", direction:"ascending"}
        ],
        hoverWidth:200,
        initialCriteria:{
            _constructor:"AdvancedCriteria",
            operator:"and",
            criteria:[
                { fieldName:"ID_STAGIONI_FK", operator:"equals", value:sceltaStagioneCorrenteForm.getStagioneCorrente() }
            ]
        },
        initWidget:function () {
            this.Super("initWidget", arguments);
            this.observe(sceltaStagioneCorrenteForm, 'aggiornaStagioneCorrenteOffline', "observer.updateFilterStagioneCorrente()")
        },
        updateFilterStagioneCorrente:function () {
            var criteria = this.getFilterEditorCriteria(true);
            if (!criteria) criteria = {};
            var formCriteria = isc.DataSource.convertCriteria(sceltaStagioneCorrenteForm.getValuesAsCriteria());
            criteria = isc.DataSource.combineCriteria(criteria, formCriteria);
            this.invalidateCache();
            this.filterData(criteria);
        }
    })
    everything works when the grid filter is empty or filtered on non-foreign keys fields.
    If I filter on a foreign key field, then when I change the form select, the combineCriteria in the 'updateFilterStagioneCorrente' is incorrect and the filter of the grid gets lost.
    you can see the generated criteria in the server side logs.
    This is correct, when I filter for the foreign key field in the grid filter
    Code:
    2013-01-14 11:13:23,440 DEBUG RPCManager Request #1 (DSRequest) payload: {
        criteria:{
            _constructor:"AdvancedCriteria",
            operator:"and",
            criteria:[
                {
                    fieldName:"ID_STAGIONI_FK",
                    operator:"equals",
                    value:1183260
                },
                {
                    fieldName:"ID_ANAGRAFICA_CLIENTI_FK",
                    operator:"equals",
                    value:170721
                }
            ]
        },
        operationConfig:{
            dataSource:"JPC_CONTRATTI",
            operationType:"fetch",
            textMatchStyle:"substring"
        },
        startRow:0,
        endRow:75,
        sortBy:[
            "CONTRATTO_NUM"
        ],
        componentId:"elencoContrattiGrid",
        appID:"builtinApplication",
        operation:"JPC_CONTRATTI_fetch",
        oldValues:{
            _constructor:"AdvancedCriteria",
            operator:"and",
            criteria:[
                {
                    fieldName:"ID_STAGIONI_FK",
                    operator:"equals",
                    value:1183260
                },
                {
                    fieldName:"ID_ANAGRAFICA_CLIENTI_FK",
                    operator:"equals",
                    value:170721
                }
            ]
        }
    }
    this is incorrect, when, right after, I change the select in the form
    Code:
    2013-01-14 11:16:01,073 DEBUG RPCManager Request #1 (DSRequest) payload: {
        criteria:{
            operator:"and",
            _constructor:"AdvancedCriteria",
            criteria:[
                {
                    fieldName:"operator",
                    operator:"iContains",
                    value:"and"
                },
                {
                    _constructor:"AdvancedCriteria",
                    operator:"or",
                    criteria:[
                        {
                            fieldName:"criteria",
                            operator:"iContains",
                            value:{
                                fieldName:"SOGGETTO_DESC",
                                operator:"iContains",
                                value:"Balocco"
                            }
                        }
                    ]
                },
                {
                    fieldName:"ID_STAGIONI_FK",
                    operator:"equals",
                    value:146969
                }
            ]
        },
        operationConfig:{
            dataSource:"JPC_CONTRATTI",
            operationType:"fetch",
            textMatchStyle:"substring"
        },
        startRow:0,
        endRow:75,
        sortBy:[
            "CONTRATTO_NUM"
        ],
        componentId:"elencoContrattiGrid",
        appID:"builtinApplication",
        operation:"JPC_CONTRATTI_fetch",
        oldValues:{
            operator:"and",
            _constructor:"AdvancedCriteria",
            criteria:[
                {
                    fieldName:"operator",
                    operator:"iContains",
                    value:"and"
                },
                {
                    _constructor:"AdvancedCriteria",
                    operator:"or",
                    criteria:[
                        {
                            fieldName:"criteria",
                            operator:"iContains",
                            value:{
                                fieldName:"SOGGETTO_DESC",
                                operator:"iContains",
                                value:"Balocco"
                            }
                        }
                    ]
                },
                {
                    fieldName:"ID_STAGIONI_FK",
                    operator:"equals",
                    value:146969
                }
            ]
        }
    }
    the latter log is with 8.2 version. 8.3 gives a different log:
    Code:
    2013-01-14 11:21:34,771 DEBUG RPCManager Request #1 (DSRequest) payload: {
        criteria:{
            operator:"and",
            _constructor:"AdvancedCriteria",
            criteria:[
                {
                    fieldName:"operator",
                    operator:"iContains",
                    value:"and"
                },
                {
                    _constructor:"AdvancedCriteria",
                    operator:"or",
                    criteria:[
                        {
                            fieldName:"criteria",
                            operator:"iContains",
                            value:{
                                fieldName:"ID_ANAGRAFICA_CLIENTI_FK",
                                operator:"equals",
                                value:170721
                            }
                        }
                    ]
                },
                {
                    fieldName:"ID_STAGIONI_FK",
                    operator:"equals",
                    value:1183260
                }
            ]
        },
        operationConfig:{
            dataSource:"JPC_CONTRATTI",
            operationType:"fetch",
            textMatchStyle:"substring"
        },
        startRow:0,
        endRow:75,
        sortBy:[
            "CONTRATTO_NUM"
        ],
        componentId:"elencoContrattiGrid",
        appID:"builtinApplication",
        operation:"JPC_CONTRATTI_fetch",
        oldValues:{
            operator:"and",
            _constructor:"AdvancedCriteria",
            criteria:[
                {
                    fieldName:"operator",
                    operator:"iContains",
                    value:"and"
                },
                {
                    _constructor:"AdvancedCriteria",
                    operator:"or",
                    criteria:[
                        {
                            fieldName:"criteria",
                            operator:"iContains",
                            value:{
                                fieldName:"ID_ANAGRAFICA_CLIENTI_FK",
                                operator:"equals",
                                value:170721
                            }
                        }
                    ]
                },
                {
                    fieldName:"ID_STAGIONI_FK",
                    operator:"equals",
                    value:1183260
                }
            ]
        }
    }
    with the chrome inspector, I can see the grid criteria (https://www.evernote.com/shard/s282/...81af3db4581639), the form criteria converted in an AdvancedCriteria (https://www.evernote.com/shard/s282/...f94baeca90c3e7), and then the combined criteria https://www.evernote.com/shard/s282/...d52553a70ecd84.

    If you could point me to a sample with a datasource with two foreign keys to different tables, I can try to make a standalone sample in the showcase
    Last edited by claudiobosticco; 15 Jan 2013, 05:28. Reason: corrected URL of 2nd image

    #2
    There probably isn't a double-FK DataSource in any sample, however, we're not sure why you think the double-FK DataSource is part of the problem - combineCriteria() has no special treatment for FKs and shouldn't need any.

    It looks more like an issue with criteria for fields that are not declared in the DataSource at all, or perhaps something more exotic in code we can't see here - please let us know if you can isolate this so that it's clearly a bug.

    Comment


      #3
      getFilterEditorCriteria seems to be the problem

      Originally posted by Isomorphic View Post
      There probably isn't a double-FK DataSource in any sample, however, we're not sure why you think the double-FK DataSource is part of the problem - combineCriteria() has no special treatment for FKs and shouldn't need any.
      actually I'm not sure that's part of the problem, but everything works when the grid filter is filtered on non-foreign keys fields, so I was looking for a similar datasource to construct a test case in the showcase.
      Originally posted by Isomorphic View Post
      It looks more like an issue with criteria for fields that are not declared in the DataSource at all, or perhaps something more exotic in code we can't see here - please let us know if you can isolate this so that it's clearly a bug.
      well, I've just added some logs in this js method:
      Code:
          updateFilterStagioneVendita:function () {
              isc.logEcho('updateFilterStagioneVendita')
              var criteria = this.getFilterEditorCriteria(true);
              if (!criteria) criteria = {};
      //        criteria._constructor = 'AdvancedCriteria'
              isc.logEcho(isc.JSON.encode(criteria), 'criteria')
              var formCriteria = isc.DataSource.convertCriteria(sceltaStagioneVenditaForm.getValuesAsCriteria());
              isc.logEcho(isc.JSON.encode(formCriteria), 'formcriteria')
              criteria = isc.DataSource.combineCriteria(criteria, formCriteria);
              isc.logEcho(isc.JSON.encode(criteria), 'combinedcriteria')
              this.invalidateCache();
              this.filterData(criteria);
          }
      and the logs are:
      Code:
      14:47:22.120:IFCS0:WARN:Log:"updateFilterStagioneVendita"
      14:47:23.886:IFCS0:WARN:Log:criteria: "{
          "operator":"and", 
          "criteria":[
              {
                  "fieldName":"ID_ANAGRAFICA_CLIENTI_FK", 
                  "operator":"equals", 
                  "value":170721
              }
          ]
      }"
      14:47:23.887:IFCS0:WARN:Log:formcriteria: "{
          "_constructor":"AdvancedCriteria", 
          "operator":"and", 
          "criteria":[
              {
                  "fieldName":"ID_STAGIONI_FK", 
                  "operator":"equals", 
                  "value":146969
              }
          ]
      }"
      14:47:23.887:IFCS0:WARN:Log:combinedcriteria: "{
          "operator":"and", 
          "_constructor":"AdvancedCriteria", 
          "criteria":[
              {
                  "fieldName":"operator", 
                  "operator":"iContains", 
                  "value":"and"
              }, 
              {
                  "_constructor":"AdvancedCriteria", 
                  "operator":"or", 
                  "criteria":[
                      {
                          "fieldName":"criteria", 
                          "operator":"iContains", 
                          "value":{
                              "fieldName":"ID_ANAGRAFICA_CLIENTI_FK", 
                              "operator":"equals", 
                              "value":170721
                          }
                      }
                  ]
              }, 
              {
                  "fieldName":"ID_STAGIONI_FK", 
                  "operator":"equals", 
                  "value":146969
              }
          ]
      }"
      the problem seems in the getFilterEditorCriteria method, which gives a criteria (the first logged) which apparently is an AdvancedCriteria, but without the _constructor attribute. If I set it like this:
      criteria._constructor = 'AdvancedCriteria'
      everything works.
      Last edited by claudiobosticco; 15 Jan 2013, 06:20.

      Comment


        #4
        Thanks for the analysis - this has been addressed in 8.3 and 9.0 - please retest with a nightly build of January 17 or later.

        Comment


          #5
          Fixed

          just tried SmartClient Version: v8.3p_2013-01-22/PowerEdition Deployment (built 2013-01-22) and I can confirm it's fixed.

          thank you very much.

          Comment

          Working...
          X