SQL Insert query from MQTT

Hello All,

This is Kartik I am trying to fetch all tag data received in array from Ignition Edge but currently I am able to fetch a single array data but I need the array data as per my array length so anyone please help me figuring this out...

Code
var array = msg.payload;
pid = "INSERT INTO [MQTT_IOT].[dbo].[Data] "
pid = pid + "(Timestamp, Name, Datatype, Value) "
pid = pid + " VALUES ('" + array[0].timestamp + "','" + array[0].name + "','" + array[0].datatype +"','"+array[0].doubleValue+"')"
msg.payload = pid
return msg;

Thanks,
Kartik I

Use a split node to convert the array into single payloads.

PS I recommend you use MSSQL-PLUS and use the UI to add parameters (avoids SQL injection) and removes the need to create a query in a function node

Thanks Steve...

Also, that isert query is not safe. Use a prepared statement and make sure that you cleanse the input variables.

This topic was automatically closed 60 days after the last reply. New replies are no longer allowed.