4 Replies Latest reply on Sep 8, 2015 12:49 PM by chadha RSS
    chengxiandu Explorer

    duplicated key in DataTable

    When I call AddDataTableEntry or AddOrUpdateDataTableEntry very quickly, two data row with same key will be added.

    How to settle it?

     

    Both serialNumber and alarmType are primary key. I have test unique primary key, but same error.

    Code:

     

    var query = {

      "filters": {

        "type": "AND",

        "filters": [

          {

            "fieldName": "serialNumber",

            "type": "EQ",

            "value": serialNumber

          },

          {

            "fieldName": "alarmType",

            "type": "EQ",

            "value": alarmType

          }

        ]

      }

    };

     

     

    var params = {

        query: query,

        maxItems: 1

    };

     

     

    var old_times = 0;

     

     

    var cc = Things["AlarmTimesTable"].QueryDataTableEntries( params );

    if ( cc !== undefined && cc.getRowCount() != 0 ) {

        old_times = cc.getRow(0).times;

        //var values = cc;//.getRow(0);

    }

     

     

    var values = Things["AlarmTimesTable"].CreateValues();

    values.gateway = me.name;

    values.updateTime = updateTime;

    values.serialNumber = serialNumber;

    values.alarmType = alarmType;

    values.times = old_times + 1;

     

     

    var params = {

        //source :  me.name,

        values : values,

    };

     

     

    Things["AlarmTimesTable"].AddOrUpdateDataTableEntry( params );

    logger.error("out");