# Insert data in sqlite without inject node

**URL:** <https://discourse.nodered.org/t/insert-data-in-sqlite-without-inject-node/20836>\
**Category:** General\
**Created:** [25 January 2020 05:45 UTC](https://discourse.nodered.org/t/insert-data-in-sqlite-without-inject-node/20836 "2020-01-25T05:45:52Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![NODE777](https://avatars.discourse-cdn.com/v4/letter/n/7993a0/32.png) [@NODE777](https://discourse.nodered.org/u/NODE777)\
**Post date:** [25 January 2020 05:45 UTC](https://discourse.nodered.org/t/insert-data-in-sqlite-without-inject-node/20836/1 "2020-01-25T05:45:52Z")

</div>

Hi There !

Can someone help me to review the function node code I've implemented to insert the two variables values **hp** and **lp** coming from a Particle Photon?  
The idea is not two use inject node but the subscription node from particle contrib which happens every 30 sec.  
The function node with red triangle has the following code:

```auto
var topic;
var data; // define variables
var hp;
var lp;
var rtmp;
var stmp;
hp=flow.get('hp') || 0; // retrive saved varaibles from the flow
lp=flow.get('lp') || 0;

**X** data= String(hp) +","+ String(lp); // create string from variables  
msg ="INSERT INTO hvac (UTC, datetimelocal,hp,lp,device) values (datetime('now'),datetime('now','localtime'),data, "Meson2"); " // from data.

msg.topic= msg;
return msg;

```

Where is a X the code show the following error message:  
I'm cannot realize how to fix that.

 ![Error message](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/f/2/f2a1720182683338b392615f7d0184977aa9a06c.png)

This is the partial flow:

 ![Nodes 1-24-20](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/3X/e/0/e07fe14dfb406ceea3c63bad46e81dee250147ef.png)

Thank you very much in advance.

---

<div class="post-metadata">

**Author:** ![zenofmud](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/zenofmud/32/316_2.png) [@zenofmud](https://discourse.nodered.org/u/zenofmud)\
**Post date:** [25 January 2020 11:16 UTC](https://discourse.nodered.org/t/insert-data-in-sqlite-without-inject-node/20836/2 "2020-01-25T11:16:07Z")

</div>

you have two issues in the `function` node. First the line starting with ` **X** data= String...` the ' **X**" is causing an error.  
secondly at the end of your INSERT you have double quotes around `Meson2` and you should change tehm to single quotes or escape them.

---

<div class="post-metadata">

**Author:** ![NODE777](https://avatars.discourse-cdn.com/v4/letter/n/7993a0/32.png) [@NODE777](https://discourse.nodered.org/u/NODE777)\
**Post date:** [26 January 2020 05:47 UTC](https://discourse.nodered.org/t/insert-data-in-sqlite-without-inject-node/20836/3 "2020-01-26T05:47:35Z")

</div>

Well, the X was just to show you were the error message was located at the code.  
I deleted the "Meson2"

And with this code modified :

```auto
var topic;
var data; // define variables
var hp;
var lp;
var rtmp;
var stmp;
hp=flow.get('hp') || 0; // retrive saved varaibles from the flow
lp=flow.get('lp') || 0;

 data= String(hp) +","+ String(lp); // create string from variables  
msg ="INSERT INTO hvac (UTC, datetimelocal,hp,lp,device) values (datetime('now'),datetime('now','localtime'),data, ); " // from data.

msg.topic= msg;
return msg;

```

I got this on the debug tab:

```auto
1/25/2020, 9:35:47 PMnode: 58b84b6f.fd0fa4
function : (error)
"Function tried to send a message of type string"

```

It seems to be that I'm failing to build the message topic to use the INSERT INTO hvac without using an inject node, i mean using function node.

I succeed to insert in db using a inject node like that:

```auto
INSERT INTO hvac (UTC, datetimelocal,hp,lp,device) values(datetime('now'),datetime('now', 'localtime'),340,89 ,"Meson2");

```

But the point is that 340 and 89 values doesn't come from variables.

Thank you for your time.

---

<div class="post-metadata">

**Author:** ![dceejay](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/dceejay/32/38_2.png) [@dceejay](https://discourse.nodered.org/u/dceejay)\
**Post date:** [26 January 2020 08:01 UTC](https://discourse.nodered.org/t/insert-data-in-sqlite-without-inject-node/20836/4 "2020-01-26T08:01:40Z")

</div>

You are over-writing msg. Just set msg.topic="INSERT... And then return msg;
