# SQLite insert problem

**URL:** <https://discourse.nodered.org/t/sqlite-insert-problem/14574>\
**Category:** General\
**Created:** [21 August 2019 00:50 UTC](https://discourse.nodered.org/t/sqlite-insert-problem/14574 "2019-08-21T00:50:59Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![goncastorena](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/goncastorena/32/3284_2.png) [@goncastorena](https://discourse.nodered.org/u/goncastorena)\
**Post date:** [21 August 2019 00:51 UTC](https://discourse.nodered.org/t/sqlite-insert-problem/14574/1 "2019-08-21T00:51:00Z")

</div>

Hello 'Im having a problem when I want to insert a variable in my data base, the variable is an flow variable that I took from a drop down list.  
when call it it says that is a char type variable but at the moment of inserting it say that there is not a column object, Object

 ![imagen](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/c/c211fb87152351d7c07799057a767cccaac3aeb5.png)

I dont know if there is any other syntax to insert a variable.  
here is my flow  
'''  
[{"id":"6a83cdb5.ea90e4","type":"function","z":"a44c1a9a.8dd15","name":"","func":"\n//var dia = new Date().toLocaleString("es-MX").slice(0,15);\n//var hora = new Date().toLocaleString("es-MX").slice(11,15).replace(/:/,"-");\n\nvar area=flow.get('garea');\nvar newMsg = {\n "topic": "INSERT INTO DATA (area,supervisor,operador,material,cantidad,fecha)"+ "VALUES("+area+",'CARLOS','ANDRES','TALADRO',5,"+msg.payload+");"\n}\n\nreturn newMsg;","outputs":1,"noerr":0,"x":860.5,"y":90,"wires":[["1fd7cd42.7c509b"]]}]  
'''

I created the Table from outside and checked that the index is a "text" type

 ![2](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/a/a9571ae872e510ee3e1da0922f54abbcc02762a3.png)

---

<div class="post-metadata">

**Author:** ![thatcadguy](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/thatcadguy/32/5273_2.png) [@thatcadguy](https://discourse.nodered.org/u/thatcadguy)\
**Post date:** [21 August 2019 01:06 UTC](https://discourse.nodered.org/t/sqlite-insert-problem/14574/2 "2019-08-21T01:06:17Z")

</div>

Looks like one of the variables you're using is an object, what are the data types of area and msg.payload?

---

<div class="post-metadata">

**Author:** ![goncastorena](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/goncastorena/32/3284_2.png) [@goncastorena](https://discourse.nodered.org/u/goncastorena)\
**Post date:** [21 August 2019 01:52 UTC](https://discourse.nodered.org/t/sqlite-insert-problem/14574/3 "2019-08-21T01:52:31Z")

</div>

Area is a char type  
 ![3](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/f/f2b31d7cc0086cb3680eff35ffce383e1c717427.png)  
and msg payload is a timestamp from the injection node

---

<div class="post-metadata">

**Author:** ![ukmoose](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ukmoose/32/13_2.png) [@ukmoose](https://discourse.nodered.org/u/ukmoose)\
**Post date:** [21 August 2019 07:15 UTC](https://discourse.nodered.org/t/sqlite-insert-problem/14574/4 "2019-08-21T07:15:06Z")

</div>

Unfortunately your flow isn't importable.

Add a debug to the output from your function and change the debug settings to  
`Output` `complete message object`

Then you will see the msg.topic you are sending and hopefully where the error is

---

<div class="post-metadata">

**Author:** ![edje11](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/edje11/32/572_2.png) [@edje11](https://discourse.nodered.org/u/edje11)\
**Post date:** [21 August 2019 08:32 UTC](https://discourse.nodered.org/t/sqlite-insert-problem/14574/5 "2019-08-21T08:32:37Z")

</div>

I'm using an Sqlite insert always like this, works fine for me.  
On the payload line you can place all your variable, it's easier then putting them inside the "insert into" string.

```auto
var version="1.01";
var temp = 23.5
etc.....

 msg2.topic = "INSERT INTO TempSensor (timestamp,nodeid,versie, temperatuur, luchtvochtigheid,status) VALUES (?,?,?,?,?,?)";
 msg2.payload = [new Date(), 101, version,temp, luchtv, status]; 

return msg2;

```

---

<div class="post-metadata">

**Author:** ![ukmoose](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/ukmoose/32/13_2.png) [@ukmoose](https://discourse.nodered.org/u/ukmoose)\
**Post date:** [21 August 2019 10:07 UTC](https://discourse.nodered.org/t/sqlite-insert-problem/14574/6 "2019-08-21T10:07:00Z")

</div>

> [@edje11](#):
>
> msg2.payload = [new Date(), 101, version,temp, luchtv, status);

That works?

---

<div class="post-metadata">

**Author:** ![edje11](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/edje11/32/572_2.png) [@edje11](https://discourse.nodered.org/u/edje11)\
**Post date:** [21 August 2019 11:07 UTC](https://discourse.nodered.org/t/sqlite-insert-problem/14574/7 "2019-08-21T11:07:26Z")

</div>

The **)** at the end should be a **]** , typo 😉  
Changed in my first reply.

---

<div class="post-metadata">

**Author:** ![thatcadguy](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/thatcadguy/32/5273_2.png) [@thatcadguy](https://discourse.nodered.org/u/thatcadguy)\
**Post date:** [21 August 2019 13:16 UTC](https://discourse.nodered.org/t/sqlite-insert-problem/14574/8 "2019-08-21T13:16:26Z")

</div>

+1, also safer to do it this way with the ?'s, as the inputs are sanitized.

---

<div class="post-metadata">

**Author:** ![goncastorena](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/goncastorena/32/3284_2.png) [@goncastorena](https://discourse.nodered.org/u/goncastorena)\
**Post date:** [22 August 2019 02:26 UTC](https://discourse.nodered.org/t/sqlite-insert-problem/14574/9 "2019-08-22T02:26:21Z")

</div>

I tried ir but I still have the error , but I checked and realize that the problem was that i was calling the variable as an object and not his payload.

 ![1](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/d/d754f3005167bb44e3bfb1fa31b66e296e383596.png)

the solution was to call it like this

 ![2](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/0/076e217d0e923f728cd7a28fea9b5ef922c7ca56.png)

---

<div class="post-metadata">

**Author:** ![goncastorena](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/goncastorena/32/3284_2.png) [@goncastorena](https://discourse.nodered.org/u/goncastorena)\
**Post date:** [22 August 2019 02:26 UTC](https://discourse.nodered.org/t/sqlite-insert-problem/14574/10 "2019-08-22T02:26:49Z")

</div>

thank you for the help 🙂
