How to get output from NodeRed Mysql node

rwahid picture rwahid · Nov 21, 2015 · Viewed 12.9k times · Source

I want to get out put from NodeRed mysql node.

Here image of connection : enter image description here

Select Query is :

msg.topic = "SELECT * t.TableID FROM booking t where t.bookingdate='"+formattedDate+"' and t.TableID = 3";

Output i am trying to get:

if(msg.payload.TableID ==3){
    var id = "15";
 var message = "Front Desk";
msg.topic = "INSERT INTO tableMessage(TableID, MESSAGE) VALUES ('"+id+"' ,'"+message+"')";

return msg;
}

Question is msg.payload.TableID ==3 is it right? is it right way to read out put from Mysql node

Select query are tested working fine. but this condition not working for me.

any one help me how to retrieve data from mysql node.

Thanks

Answer

hardillb picture hardillb · Nov 21, 2015

The output from the mysql node is an array of rows so your test should be something like this:

if (msg.payload[0].TableID ==3) {
...

EDIT: You can test if no results were returned by testing the content of msg.payload

if (!msg.payload) {
  //no results
} else if (msg.payload[0].TableID == 3) {
  //results
}