appreciate your help , if you can verify the following program
var topic =msg.topic;
var a = msg.payload.V1;
var b = msg.payload.V2;
var c = msg.payload.V3;
payload = 'INSERT INTO meter(V1,V2,V3) VALUES ("a","b","c")'
msg.payload=payload;
return msg
That is certainly closer however you need to read the help info for the SQL node on the right-hand sidebar - it will tell you how to pass a SQL command.
To get you moving, this will likely be closer (but you need to understand how to correctly pass parameters to the SQL node to avoid possible SQL injection hacks)...
var a = msg.payload.V1;
var b = msg.payload.V2;
var c = msg.payload.V3;
msg.topic = `INSERT INTO meter(V1,V2,V3) VALUES (${a}, ${b}, ${c})`
return msg;
Along with Steve sample query , additional lines added in query. Initially the flow was successfully deployed and got output in DB too..
var sql =' ';
var a = msg.payload.V1;
var b = msg.payload.V2;
var c = msg.payload.V3;
var outputs = ;
sql = 'INSERT INTO meter (V1,V2,V3) VALUE ({a},{b},${c})'
outputs.push({topic:sql});
return [ outputs ];
Another issue is raised :
"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 '{a},{b},{c})' at line 1"
Appreciate , if some one help me in resolving it
thank you !
Check the example I posted. I used ` backticks around the string. This is known as a template literal. This is what makes ${a} turn into a variable value.
You didn't. You used single quotes and you missed out the $ symbol...
var sql ="";
var a = msg.payload.V1;
var b = msg.payload.V2;
var c = msg.payload.V3;
var outputs = ;
sql = 'INSERT INTO meter (V1,V2,V3) VALUES ({a},{b},${c})'
outputs.push({topic:sql});
return [ outputs ];
Issue raised:
"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 '{a},{b},{c})' at line 1"
Issue :
"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 '{a},{b},{c})' at line 1"
var sql=" ";
var a = msg.payload.V1;
var b = msg.payload.V2;
var c = msg.payload.V3;
var outputs = ;
sql = 'INSERT INTO meter ( V1,V2,V3) VALUES ({a}, {b}, ${c})';