after insert trigger does not work when insert happens from node js app

I have a after insert trigger. that calls a stored procedure .when I run a direct query it works well. but when I insert data through node js app . it does not even insert data in main table . There is not any error in trigger and stored procedure cause it works with direct insert query for the table .

dbObject.create(data, function(err, response){
        if (err) {
            //console.log("err", err);
            res.status(500).jsonp(response)
        }
        console.log("response", response);
        dbObject.find({SnsId: SnsId}, '*' , {}, 0, 0, {}, function(err, resp){
            if (err) {
                //console.log("err", err);
                res.status(500).jsonp(err)
            }
            console.log("response", resp);
            res.jsonp(resp);
        });
    });

trigger code --

DELIMITER $$
CREATE TRIGGER `copytoSensorMapTrigger` AFTER INSERT ON test4.`SENSORS`
FOR EACH ROW
BEGIN
   CALL copyToSensorMap(NEW.`SnsId`,NEW.`SnsState`);
END;

Stored Procedure code --

DELIMITER $$
 CREATE PROCEDURE copyToSensorMap(IN snsid bigint(20),IN sns_state varchar(128))
   BEGIN
   DECLARE  color varchar(128);
   INSERT INTO test3.`SENSOR_MAP` (`SENSOR_ID`, `SENSOR_NAME`, `USER_ID`, `HOST_ID`,  `SENSOR_STATE`)
    SELECT `SnsId`,
   `SnsName`,`SnsOwner`,`HostId`,`SnsState`
         FROM test4.`SENSORS`
         where test4.`SENSORS`.`SnsId`=snsid;
    IF ( sns_state ='Unassigned') THEN
        set color = 'Grey';
    ELSEIF ( sns_state ='Running') THEN
     set color = 'Green';
    END IF;
    update test3.`SENSOR_MAP`
       set test3.`SENSOR_MAP`.`SENSOR_COLOR` = color
       where test3.`SENSOR_MAP`.`SENSOR_ID` = snsid;
UPDATE test3.`SENSOR_MAP`
  INNER JOIN test4.`HOSTS`
    ON (test3.`SENSOR_MAP`.`HOST_ID` = test4.`HOSTS`.id)
  SET 
    test3.`SENSOR_MAP`.HOST_NAME = test4.HOSTS.Name,
    test3.`SENSOR_MAP`.LATITUDE = test4.HOSTS.GpsLatitude,
    test3.`SENSOR_MAP`.LONGITUDE = test4.HOSTS.GpsLongitude;
UPDATE test3.`SENSOR_MAP`
  INNER JOIN test4.`users` ON (test3.`SENSOR_MAP`.`USER_ID` = test4.`users`.id)
  SET 
    test3.`SENSOR_MAP`.USER_NAME = test4.users.user;
UPDATE  test3.`SENSOR_MAP`  c
    INNER JOIN
    (
        select a.`SnsId`,b.id,b.ServiceName,b.ServiceType
           from test4.sensors as a
           join test4.SESSIONS as b  on a.SessionId =b.id
           where a.`SnsId` =snsid
           group by `SnsId` 
    ) d  ON c.SENSOR_ID = d.`SnsId`
    SET c.SESSION_NAME = d.ServiceName,
        c.SESSION_TYPE = d.ServiceType;
END $$

I am using Mysql database and storage engine is InnoDB. I have checked the sql query . it is forming with SET Keyword. does Mysql insert query with set keyword support after insert stored procedure.

Issue is solved now. it was a table name in all caps in Mysql and I had written in lowercase.tables names were "user" and "sensor" . now it is solved.

Answers


I would also recommend to use return in the places you check for errors, otherwise the code will continue and not stop in case of errors.

Try using this code:

dbObject.create(data, function(err, response){
    if (err) {
        //console.log("err", err);
        return res.status(500).jsonp(response)
    }
    console.log("response", response);
    dbObject.find({SnsId: SnsId}, '*' , {}, 0, 0, {}, function(err, resp){
        if (err) {
            //console.log("err", err);
            return res.status(500).jsonp(err)
        }
        console.log("response", resp);
        res.jsonp(resp);
    });
});

Need Your Help

Execute .py script from sikuli passing arguments

python numpy jython sikuli

I have a code to be executed in Sikuli, and I want to call an external Python Script to analyze the data from a generated file.