Cant use variable in Mysql query

46 views
Skip to first unread message

tom reitsema

unread,
Sep 21, 2017, 4:48:30 PM9/21/17
to Node-RED
Hi,

I'm using an arduino for collecting some data and I want to send it to my MySql database.

I first split the incoming data: 56'51'34'67

and then i put it in different variables, but when i use that variable in my query it doesnt work!


can somebody please tell me what i am doing wrong?

code:


var outputMsgs = [];
var words = msg.payload.split("'");
for (var w in words) {
    outputMsgs.push({payload:words[w]});
    
}
var msg1 = outputMsgs[0];
var msg2 = outputMsgs[1];
var msg3 = outputMsgs[2];
var msg4 = outputMsgs[3];


var newMsg = { payload: msg1 };
newMsg.topic="insert into Sensor_data (naam,payload) values ('0',"+newMsg.payload+")";
return newMsg;


thanks in advance

tom

Colin Law

unread,
Sep 21, 2017, 4:54:03 PM9/21/17
to node...@googlegroups.com
If you feed that into a debug node do you see what you expect?

If not try to work out why.

Colin
> --
> http://nodered.org
>
> Join us on Slack to continue the conversation: http://nodered.org/slack
> ---
> You received this message because you are subscribed to the Google Groups
> "Node-RED" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to node-red+u...@googlegroups.com.
> To post to this group, send email to node...@googlegroups.com.
> Visit this group at https://groups.google.com/group/node-red.
> To view this discussion on the web, visit
> https://groups.google.com/d/msgid/node-red/757baec9-e99a-447f-b8d2-0a046081360d%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.

tom reitsema

unread,
Sep 21, 2017, 5:01:59 PM9/21/17
to Node-RED
i get this when i input the data: 51'56'57'78'



insert into Sensor_data (naam,payload) values ('0',[object Object]) : msg.payload : Object
object
payload"51"
it is what i want but then i get from the mysql node this:

Error: ER_PARSE_ERROR: You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near '[object Object])' at line 1




Op donderdag 21 september 2017 22:54:03 UTC+2 schreef Colin Law:

Mark Setrem

unread,
Sep 21, 2017, 5:08:44 PM9/21/17
to Node-RED
As shown in your debug message your msg.topic is 

insert into Sensor_data (naam,payload) values ('0',[object Object]) 

What do you want your msg.topic to be ?

Colin Law

unread,
Sep 21, 2017, 5:18:54 PM9/21/17
to node...@googlegroups.com
If you select the Complete Message mode for the debug it may be easier
to see exactly what you have. You can click on the objects to expand
them.

Colin
> https://groups.google.com/d/msgid/node-red/efa95571-6a9e-40aa-a5b0-076b13c24c83%40googlegroups.com.

tom reitsema

unread,
Sep 21, 2017, 5:35:18 PM9/21/17
to Node-RED
I get the same errors :(

Colin Law

unread,
Sep 22, 2017, 2:03:33 AM9/22/17
to node...@googlegroups.com
You have not answered the question. Are the topic and payload set to what you want and if not then exactly what do you want there?

On 21 Sep 2017 10:35 p.m., "tom reitsema" <tomre...@gmail.com> wrote:
I get the same errors :(

--
http://nodered.org

Join us on Slack to continue the conversation: http://nodered.org/slack
---
You received this message because you are subscribed to the Google Groups "Node-RED" group.
To unsubscribe from this group and stop receiving emails from it, send an email to node-red+unsubscribe@googlegroups.com.
To post to this group, send an email to node...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages