Open RoWi2907 opened 3 years ago
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;
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;
//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)';
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?