Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
RoWi2907 opened this issue Feb 15, 2021 · 3 comments
Open

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

RoWi2907 opened this issue Feb 15, 2021 · 3 comments

Comments

@RoWi2907
Copy link

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. (#1)

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

@Nikoolayy1
Copy link

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;

@BuchananFab
Copy link

BuchananFab commented Jul 17, 2021

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
Copy link

BuchananFab commented Jul 17, 2021

//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)';

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants