node-red-contrib-stackhero-mysql icon indicating copy to clipboard operation
node-red-contrib-stackhero-mysql copied to clipboard

msg.payload should be an object containing the query arguments.

Open RoWi2907 opened this issue 4 years ago • 3 comments

Since a few days I get an error message with an empty payload, when trying to request data from my database. The flow was working before without issues providing the request via the message topic. I'm running 1.0.5.

This issue was reported before and appeared to be solved with version 1.0.3. (https://github.com/stackhero-io/node-red-contrib-stackhero-mysql/issues/1)

What do I need to put into the payload when I want to retrieve data from the db?

RoWi2907 avatar Feb 15 '21 16:02 RoWi2907

Just use a fynction object and there add the code and you inject node should just trigger it as per the example at https://flows.nodered.org/node/node-red-contrib-stackhero-mysql:

msg.topic = 'SELECT * FROM users WHERE name = :name AND age > :age;'; msg.payload = { name: 'Adrien', age: 30 }; return msg;

Nikoolayy1 avatar Jul 02 '21 20:07 Nikoolayy1

Switching a working flow from the (node-red-node-mysql) node to this, I encounter the same error. It seems it's because the (node-red-node-mysql) node accepts an array for msg.payload arguments. I cannot seem to format this to work as an object. Any suggestions?

//Works with (node-red-node-mysql): msg.payload = [tag1, tag2]; msg.topic = 'INSERT INTO MY_DB(Time, Psi) VALUES (?,?)';

//Causes sql syntax error with MariaDB: msg.payload = {tag1, tag2}; msg.topic = 'INSERT INTO MY_DB(Time, Psi) VALUES (?,?)';

//Complete function node: var data = msg.payload; var ts_string = data._time; var tag1 = Date.parse(ts_string)/1000; var tag2 = data._value; msg.payload = [tag1, tag2]; msg.topic = 'INSERT INTO MY_DB(Time, Psi) VALUES (?,?)'; return msg;

BuchananFab avatar Jul 17 '21 02:07 BuchananFab

//Solution was changing this: msg.payload = [tag1, tag2]; msg.topic = 'INSERT INTO MY_DB(Time, Psi) VALUES (?,?)'; //to this: msg.payload = {tag1, tag2}; msg.topic = 'INSERT INTO MY_DB(Time, Psi) VALUES (:tag1,:tag2)';

BuchananFab avatar Jul 17 '21 02:07 BuchananFab