# Saving Data in DB at SQLite Function - Help!

**URL:** <https://discourse.nodered.org/t/saving-data-in-db-at-sqlite-function-help/4789>\
**Category:** General\
**Created:** [12 November 2018 10:23 UTC](https://discourse.nodered.org/t/saving-data-in-db-at-sqlite-function-help/4789 "2018-11-12T10:23:15Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![wtrk](https://avatars.discourse-cdn.com/v4/letter/w/97f17d/32.png) [@wtrk](https://discourse.nodered.org/u/wtrk)\
**Post date:** [12 November 2018 10:23 UTC](https://discourse.nodered.org/t/saving-data-in-db-at-sqlite-function-help/4789/1 "2018-11-12T10:23:15Z")

</div>

Hi everyone. I looked almost all SQLite topic and didnt get solve my problem.  
I created a flow and testing local. Connected DHT11 and 1 cable for test.

I can take sensor values and also GPIO port connected or not connected. But I didnt succeed it to save in DB at SQLİte. DB files is creating in my RPI local.

I installed SQLite but dont have experience about function code. Can some one help me about function code how should be it ?

I also adding some screen shot and my flow. Thanks for your helps.

My Function node is ;

> new Date(2018, 11 , 12, 11, 04,0)  
> var \_resultDate = d.toLocaleDateString('de-CH', options);  
> msg.payload = \_resultDate + ' T:' + msg.payload + ' H:' + msg.humidity;  
> return msg;

Flow

```auto
[{"id":"b6f00e41.761ef","type":"rpi-gpio in","z":"f833ce19.4b7f2","name":"","pin":"40","intype":"tri","debounce":"25","read":false,"x":150,"y":120,"wires":[["6cf8d1c6.c57b1"]]},{"id":"6cf8d1c6.c57b1","type":"dsm","z":"f833ce19.4b7f2","name":"state right","sm_config":"{\n \"triggerInput\": \"payload\",\n \"currentState\": \"running\",\n \"states\": {\n \"stopped\": {\n \"0\": \"running\"\n },\n \"running\": {\n \"1\": \"stopped\"\n }\n },\n \"methods\": {\n \"onBeforeTransition\": \"msg.pyload = msg.payload.toString();\",\n \"0\": \"sta.fill='green';msg.background='green';msg.label='Laser 1 Working';\",\n \"1\": \"sta.fill='red';msg.background='red';msg.label='Laser 1 Error!!!';\"\n }\n}","x":336,"y":118,"wires":[["ce065d9c.2bf7d","698821cf.9c9ad"]]},{"id":"ce065d9c.2bf7d","type":"ui_button","z":"f833ce19.4b7f2","name":"Laser 1","group":"7fe16ebd.2f6bb","order":0,"width":0,"height":0,"passthru":false,"label":"{{msg.label}}","color":"","bgcolor":"{{msg.background}}","icon":"","payload":"","payloadType":"str","topic":"","x":500,"y":120,"wires":[[]]},{"id":"206a0f23.962e3","type":"sqlite","z":"f833ce19.4b7f2","mydb":"3a0f3358.0ee28c","sqlquery":"msg.topic","sql":"","name":"Sqlite","x":670,"y":80,"wires":[[]]},{"id":"698821cf.9c9ad","type":"function","z":"f833ce19.4b7f2","name":"Record","func":"","outputs":1,"noerr":0,"x":500,"y":80,"wires":[["206a0f23.962e3"]]},{"id":"1eedbd33.6bf773","type":"ui_gauge","z":"f833ce19.4b7f2","name":"Temp Gauge","group":"51d39551.b1d77c","order":0,"width":0,"height":0,"gtype":"gage","title":"Temp Gauge","label":"°C","format":"{{value}}","min":0,"max":"35","colors":["#00b500","#fb9b44","#ca3838"],"seg1":"","seg2":"","x":710,"y":260,"wires":[]},{"id":"30d30a4b.5b8a76","type":"ui_gauge","z":"f833ce19.4b7f2","name":"Humid Gauge","group":"ca64eeb9.03b0c","order":0,"width":0,"height":0,"gtype":"gage","title":"Humid Gauge","label":"%","format":"{{value}}","min":0,"max":"50","colors":["#00b500","#e6e600","#ca3838"],"seg1":"","seg2":"","x":700,"y":400,"wires":[]},{"id":"487c05d4.5fafcc","type":"ui_chart","z":"f833ce19.4b7f2","name":"Humid Graph","group":"ca64eeb9.03b0c","order":0,"width":0,"height":0,"label":"Humid Graph","chartType":"line","legend":"false","xformat":"HH:mm:ss","interpolate":"linear","nodata":"","dot":false,"ymin":"0","ymax":"100","removeOlder":"1","removeOlderPoints":"","removeOlderUnit":"3600","cutout":0,"useOneColor":false,"colors":["#1f77b4","#aec7e8","#ff7f0e","#2ca02c","#98df8a","#d62728","#ff9896","#9467bd","#c5b0d5"],"useOldStyle":false,"x":690,"y":360,"wires":[[],[]]},{"id":"3d877289.a4cd3e","type":"ui_chart","z":"f833ce19.4b7f2","name":"Temp Graph","group":"51d39551.b1d77c","order":0,"width":0,"height":0,"label":"Temp Graph","chartType":"line","legend":"false","xformat":"HH:mm:ss","interpolate":"linear","nodata":"","dot":false,"ymin":"0","ymax":"50","removeOlder":"1","removeOlderPoints":"","removeOlderUnit":"3600","cutout":0,"useOneColor":false,"colors":["#1f77b4","#aec7e8","#ff7f0e","#2ca02c","#98df8a","#d62728","#ff9896","#9467bd","#c5b0d5"],"useOldStyle":false,"x":705.0000267028809,"y":226.00000381469727,"wires":[[],[]]},{"id":"92a455b6.ad22e8","type":"function","z":"f833ce19.4b7f2","name":"Humidity","func":"msg.payload = msg.humidity;\nreturn msg;","outputs":1,"noerr":0,"x":500,"y":340,"wires":[["30d30a4b.5b8a76","487c05d4.5fafcc","7763bb14.c0cfe4"]]},{"id":"1bbe8187.919a2e","type":"function","z":"f833ce19.4b7f2","name":"Temperature","func":"msg.payload = msg.payload;\nreturn msg;","outputs":1,"noerr":0,"x":509.9999656677246,"y":298.9999933242798,"wires":[["1eedbd33.6bf773","3d877289.a4cd3e","7763bb14.c0cfe4"]]},{"id":"f20a0124.8beab","type":"rpi-dht22","z":"f833ce19.4b7f2","name":"","topic":"Isi/Nem","dht":"11","pintype":"0","pin":4,"x":300,"y":320,"wires":[["92a455b6.ad22e8","1bbe8187.919a2e"]]},{"id":"a7f66a47.d2f538","type":"rpi-gpio in","z":"f833ce19.4b7f2","name":"","pin":"7","intype":"tri","debounce":"25","read":false,"x":110,"y":340,"wires":[["f20a0124.8beab"]]},{"id":"8e763e28.d77a5","type":"inject","z":"f833ce19.4b7f2","name":"","topic":"","payload":"","payloadType":"date","repeat":"30","crontab":"","once":false,"onceDelay":0.1,"x":135.52993392944336,"y":306.3500499725342,"wires":[["f20a0124.8beab"]]},{"id":"7763bb14.c0cfe4","type":"function","z":"f833ce19.4b7f2","name":"Rec Function","func":"new Date(2018, 11 , 12, 11, 04,0)\nvar _resultDate = d.toLocaleDateString('de-CH', options);\n\n//var d = new Date(2018, 11, 24, 10, 33, 30, 0);\nmsg.payload = _resultDate + ' T:' + msg.payload + ' H:' + msg.humidity;\nreturn msg;","outputs":1,"noerr":0,"x":769.5299110412598,"y":301.350022315979,"wires":[["ac9435a0.fbc6b8","4f988ac8.e745f4"]]},{"id":"4f988ac8.e745f4","type":"e-mail","z":"f833ce19.4b7f2","server":"53.151.100.102","port":"25","secure":false,"name":"//tarik.bellikli@daimler.com","dname":"Mail","x":970,"y":340,"wires":[]},{"id":"ac9435a0.fbc6b8","type":"sqlite","z":"f833ce19.4b7f2","mydb":"3a0f3358.0ee28c","sqlquery":"msg.topic","sql":"","name":"Sql","x":970,"y":260,"wires":[[]]},{"id":"7fe16ebd.2f6bb","type":"ui_group","z":"","name":"Assembly Lines","tab":"6809cbe4.c8aa24","disp":true,"width":"6","collapse":false},{"id":"3a0f3358.0ee28c","type":"sqlitedb","z":"","db":"/var/www/html/database/LaserDB","mode":"RWC"},{"id":"51d39551.b1d77c","type":"ui_group","z":"","name":"Assembly Lines ","tab":"6809cbe4.c8aa24","disp":true,"width":"6","collapse":false},{"id":"ca64eeb9.03b0c","type":"ui_group","z":"","name":"Assembly Lines ","tab":"6809cbe4.c8aa24","disp":true,"width":"6","collapse":false},{"id":"6809cbe4.c8aa24","type":"ui_tab","z":"","name":"Chasis Lines","icon":"dashboard"}]

```

Screenshot

 ![1](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/c/cd945a1731793d2676b0bd2eb909e21e44429916.png) ![2](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/6/6cf485f599cfd9ff37988d6e778271fe16f1cdce.png) ![3](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/6/625c58c2de58a4aed16f52e72e50e2d96f2db597.png)

---

<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:** [12 November 2018 10:43 UTC](https://discourse.nodered.org/t/saving-data-in-db-at-sqlite-function-help/4789/2 "2018-11-12T10:43:32Z")

</div>

So where exactly is your SQL? If you are doing an insert you must use an `insert` statement.

If you don't know SQL I would suggest you start off by taking a tutorial like [https://www.w3schools.com/sql/](https://www.w3schools.com/sql/)

`As I suggested to you 3 days ago in the other thread`, you should to the 'FLOWS' section of this website and search for 'flows' (not 'nodes') that contain the word 'sqlite' and see what shows up.

---

<div class="post-metadata">

**Author:** ![wtrk](https://avatars.discourse-cdn.com/v4/letter/w/97f17d/32.png) [@wtrk](https://discourse.nodered.org/u/wtrk)\
**Post date:** [12 November 2018 11:00 UTC](https://discourse.nodered.org/t/saving-data-in-db-at-sqlite-function-help/4789/3 "2018-11-12T11:00:08Z")

</div>

I looked but didnt find it about what I want, maybe I mistook.

My SQL is in there, which is I showing in picture.

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

---

<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:** [12 November 2018 12:14 UTC](https://discourse.nodered.org/t/saving-data-in-db-at-sqlite-function-help/4789/4 "2018-11-12T12:14:08Z")

</div>

You clearly need to take a course on SQL. I suggest you take a step back and take the W3Schools tutorial I previously suggested. Once you complete it you should have a better handle on things.

---

<div class="post-metadata">

**Author:** ![wtrk](https://avatars.discourse-cdn.com/v4/letter/w/97f17d/32.png) [@wtrk](https://discourse.nodered.org/u/wtrk)\
**Post date:** [12 November 2018 12:21 UTC](https://discourse.nodered.org/t/saving-data-in-db-at-sqlite-function-help/4789/5 "2018-11-12T12:21:33Z")

</div>

> [@zenofmud](#):
>
> ed to

If I have free time I will, but at the moment want to complete it. I need some working examples. Basically I want to save my data in SQL not more today.

---

<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:** [12 November 2018 12:28 UTC](https://discourse.nodered.org/t/saving-data-in-db-at-sqlite-function-help/4789/6 "2018-11-12T12:28:23Z")

</div>

> [@wtrk](#):
>
> I need some working examples.

Then go back and do the search I have told you twice before to do - go to the `flows` tab and type into the searchbox 'sqlite' and look at the 'flows' examples.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [12 November 2018 12:32 UTC](https://discourse.nodered.org/t/saving-data-in-db-at-sqlite-function-help/4789/7 "2018-11-12T12:32:16Z")

</div>

> [@wtrk](#):
>
> My SQL is in there, which is I showing in picture.

To insert data into a database you need an `insert` SQL statement. There does not seem to be any such statement in your posts. That is what was meant when asking where your SQL is.

---

<div class="post-metadata">

**Author:** ![wtrk](https://avatars.discourse-cdn.com/v4/letter/w/97f17d/32.png) [@wtrk](https://discourse.nodered.org/u/wtrk)\
**Post date:** [12 November 2018 12:47 UTC](https://discourse.nodered.org/t/saving-data-in-db-at-sqlite-function-help/4789/8 "2018-11-12T12:47:55Z")

</div>

> [@zenofmud](#):
>
> > [@wtrk](#):
> >
> > I need some working examples.
> 
> Then go back and do the search I have told you twice before to do - go to the `flows` tab and type into the searchbox 'sqlite' and look at the 'flows' examples.

I found 3 example in flows but this are not clear for me. Thanks.

---

<div class="post-metadata">

**Author:** ![wtrk](https://avatars.discourse-cdn.com/v4/letter/w/97f17d/32.png) [@wtrk](https://discourse.nodered.org/u/wtrk)\
**Post date:** [12 November 2018 13:16 UTC](https://discourse.nodered.org/t/saving-data-in-db-at-sqlite-function-help/4789/9 "2018-11-12T13:16:36Z")

</div>

Dear @Colin I created a DB manually in phpliteadmin.  
But when I choose sqlite node and want to connect this DB it gives an error below.

> 12.11.2018 16:12:08[node: 4b233758.7dab88](http://192.168.1.124:1880/#)msg : error
> 
> "Error: SQLITE\_READONLY: attempt to write a readonly database"

So first I have to solve SQLite readonliy problem. Then I need to Function node code , for saving data in SQL

---

<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:** [12 November 2018 13:22 UTC](https://discourse.nodered.org/t/saving-data-in-db-at-sqlite-function-help/4789/10 "2018-11-12T13:22:44Z")

</div>

You need to learn how to do the basic SQL commands: INSERT, UPDATE, SELECT and DELETE

go and install the flow: `Database examples - insert and select using binding` and after you install it and look at it and play with it, if you still don't know how to insert your data come back and show us what you have tried (include your flo0 and then ask for help.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [12 November 2018 13:34 UTC](https://discourse.nodered.org/t/saving-data-in-db-at-sqlite-function-help/4789/11 "2018-11-12T13:34:10Z")

</div>

> [@wtrk](#):
>
> "Error: SQLITE\_READONLY: attempt to write a readonly database"

That probably means that the user running node red does not have write access to the file.

---

<div class="post-metadata">

**Author:** ![wtrk](https://avatars.discourse-cdn.com/v4/letter/w/97f17d/32.png) [@wtrk](https://discourse.nodered.org/u/wtrk)\
**Post date:** [12 November 2018 14:07 UTC](https://discourse.nodered.org/t/saving-data-in-db-at-sqlite-function-help/4789/12 "2018-11-12T14:07:22Z")

</div>

> [@zenofmud](#):
>
> You need to learn how to do the basic SQL commands: INSERT, UPDATE, SELECT and DELETE
> 
> go and install the flow: `Database examples - insert and select using binding` and after you install it and look at it and play with it, if you still don't know how to insert your data come back and show us what you have tried (include your flo0 and then ask for help.

I did this a few times but again will look. Thanks.

---

<div class="post-metadata">

**Author:** ![wtrk](https://avatars.discourse-cdn.com/v4/letter/w/97f17d/32.png) [@wtrk](https://discourse.nodered.org/u/wtrk)\
**Post date:** [13 November 2018 05:36 UTC](https://discourse.nodered.org/t/saving-data-in-db-at-sqlite-function-help/4789/13 "2018-11-13T05:36:03Z")

</div>

> [@Colin](#):
>
> > [@wtrk](#):
> >
> > "Error: SQLITE\_READONLY: attempt to write a readonly database"
> 
> That probably means that the user running node red does not have write access to the file.

I solved this problem with belowing code and changed permission. Now I will try to connect db

> sudo chown user file

---

<div class="post-metadata">

**Author:** ![wtrk](https://avatars.discourse-cdn.com/v4/letter/w/97f17d/32.png) [@wtrk](https://discourse.nodered.org/u/wtrk)\
**Post date:** [13 November 2018 06:12 UTC](https://discourse.nodered.org/t/saving-data-in-db-at-sqlite-function-help/4789/14 "2018-11-13T06:12:30Z")

</div>

> [@zenofmud](#):
>
> You need to learn how to do the basic SQL commands: INSERT, UPDATE, SELECT and DELETE
> 
> go and install the flow: `Database examples - insert and select using binding` and after you install it and look at it and play with it, if you still don't know how to insert your data come back and show us what you have tried (include your flo0 and then ask for help.

I have done it I think. My problem is RPI 3 is near by me right now, and when I want to connect and discconect GPIO 40 any device, want to save this value in DB. SO what kind of way I follow your advice ?

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

---

<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:** [13 November 2018 11:13 UTC](https://discourse.nodered.org/t/saving-data-in-db-at-sqlite-function-help/4789/15 "2018-11-13T11:13:49Z")

</div>

add a `rpi gpio` input node and point it at that gpio. Now you will have it's state and you can add it to an SQL insert statement.

---

<div class="post-metadata">

**Author:** ![wtrk](https://avatars.discourse-cdn.com/v4/letter/w/97f17d/32.png) [@wtrk](https://discourse.nodered.org/u/wtrk)\
**Post date:** [13 November 2018 11:24 UTC](https://discourse.nodered.org/t/saving-data-in-db-at-sqlite-function-help/4789/16 "2018-11-13T11:24:08Z")

</div>

Dear zenofmud I added **Rpi gpio** and tried this function code, but didnt worked properly. I gives an error in picture below.  
Also this is my flow 🙂

```auto
[{"id":"e1440866.15e6d8","type":"rpi-gpio in","z":"2127666b.508a1a","name":"","pin":"40","intype":"tri","debounce":"25","read":false,"x":290,"y":160,"wires":[["bf824466.157438"]]},{"id":"bf824466.157438","type":"dsm","z":"2127666b.508a1a","name":"state right","sm_config":"{\n \"triggerInput\": \"payload\",\n \"currentState\": \"running\",\n \"states\": {\n \"stopped\": {\n \"0\": \"running\"\n },\n \"running\": {\n \"1\": \"stopped\"\n }\n },\n \"methods\": {\n \"onBeforeTransition\": \"msg.pyload = msg.payload.toString();\",\n \"0\": \"sta.fill='green';msg.background='green';msg.label='Laser 1 Working';\",\n \"1\": \"sta.fill='red';msg.background='red';msg.label='Laser 1 Error!!!';\"\n }\n}","x":476,"y":158,"wires":[["efa69de4.0f812"]]},{"id":"efa69de4.0f812","type":"ui_button","z":"2127666b.508a1a","name":"Laser 1","group":"60d4f788.2f0518","order":0,"width":0,"height":0,"passthru":false,"label":"{{msg.label}}","color":"","bgcolor":"{{msg.background}}","icon":"","payload":"","payloadType":"str","topic":"","x":660,"y":160,"wires":[[]]},{"id":"fa3c9670.4307c8","type":"ui_gauge","z":"2127666b.508a1a","name":"Temp Gauge","group":"10353f56.f3abf1","order":0,"width":0,"height":0,"gtype":"gage","title":"Temp Gauge","label":"°C","format":"{{value}}","min":0,"max":"50","colors":["#00b500","#fb9b44","#ca3838"],"seg1":"","seg2":"","x":730,"y":340,"wires":[]},{"id":"5c607992.753da8","type":"ui_gauge","z":"2127666b.508a1a","name":"Humid Gauge","group":"ee18ca73.bf61a8","order":0,"width":0,"height":0,"gtype":"gage","title":"Humid Gauge","label":"%","format":"{{value}}","min":0,"max":"100","colors":["#00b500","#e6e600","#ca3838"],"seg1":"","seg2":"","x":740,"y":500,"wires":[]},{"id":"afe8ec98.457f8","type":"ui_chart","z":"2127666b.508a1a","name":"Humid Graph","group":"ee18ca73.bf61a8","order":0,"width":0,"height":0,"label":"Humid Graph","chartType":"line","legend":"false","xformat":"HH:mm:ss","interpolate":"linear","nodata":"","dot":false,"ymin":"0","ymax":"100","removeOlder":"1","removeOlderPoints":"","removeOlderUnit":"3600","cutout":0,"useOneColor":false,"colors":["#1f77b4","#aec7e8","#ff7f0e","#2ca02c","#98df8a","#d62728","#ff9896","#9467bd","#c5b0d5"],"useOldStyle":false,"x":736.9999809265137,"y":464.0000534057617,"wires":[[],[]]},{"id":"40b38fad.4ebf6","type":"ui_chart","z":"2127666b.508a1a","name":"Temp Graph","group":"10353f56.f3abf1","order":0,"width":0,"height":0,"label":"Temp Graph","chartType":"line","legend":"false","xformat":"HH:mm:ss","interpolate":"linear","nodata":"","dot":false,"ymin":"0","ymax":"50","removeOlder":"1","removeOlderPoints":"","removeOlderUnit":"3600","cutout":0,"useOneColor":false,"colors":["#1f77b4","#aec7e8","#ff7f0e","#2ca02c","#98df8a","#d62728","#ff9896","#9467bd","#c5b0d5"],"useOldStyle":false,"x":725.0000267028809,"y":306.00000381469727,"wires":[[],[]]},{"id":"f581843b.454128","type":"function","z":"2127666b.508a1a","name":"Humidity","func":"msg.payload = msg.humidity;\nreturn msg;","outputs":1,"noerr":0,"x":480,"y":460,"wires":[["5c607992.753da8","afe8ec98.457f8","c6ca889f.ed57c8"]]},{"id":"24051d5d.099df2","type":"function","z":"2127666b.508a1a","name":"Temperature","func":"msg.payload = msg.payload;\nreturn msg;","outputs":1,"noerr":0,"x":490,"y":420,"wires":[["fa3c9670.4307c8","40b38fad.4ebf6","c6ca889f.ed57c8"]]},{"id":"830308e6.e94f08","type":"rpi-dht22","z":"2127666b.508a1a","name":"","topic":"Temp/Humid","dht":"11","pintype":"0","pin":4,"x":306.9999580383301,"y":449.00000858306885,"wires":[["f581843b.454128","24051d5d.099df2"]]},{"id":"65103e0d.42d9b","type":"rpi-gpio in","z":"2127666b.508a1a","name":"","pin":"7","intype":"tri","debounce":"25","read":false,"x":121.99995803833008,"y":447.00000858306885,"wires":[["830308e6.e94f08"]]},{"id":"b8266054.05733","type":"inject","z":"2127666b.508a1a","name":"","topic":"","payload":"","payloadType":"date","repeat":"30","crontab":"","once":false,"onceDelay":0.1,"x":135.52993392944336,"y":406.3500499725342,"wires":[["830308e6.e94f08"]]},{"id":"f3874443.03a2f8","type":"debug","z":"2127666b.508a1a","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","x":1150,"y":360,"wires":[]},{"id":"c6ca889f.ed57c8","type":"function","z":"2127666b.508a1a","name":"Insert Statement","func":"var outputs = [] ;\n\nsql = \"INSERT INTO Status (Device,Value)\" +\n\"VALUES ('Temperature', \"+ msg.payload +\")\";\noutputs.push({topic:sql});\nsql = \"INSERT INTO Status (Device,Value)\" +\n\"VALUES ('Humidity', \"+ msg.humidity +\")\";\noutputs.push({topic:sql});\nreturn msg;","outputs":1,"noerr":0,"x":880,"y":400,"wires":[["a7903d61.7f9be","f3874443.03a2f8"]]},{"id":"a7903d61.7f9be","type":"sqlite","z":"2127666b.508a1a","mydb":"8766660e.a1b488","sqlquery":"msg.topic","sql":"","name":"RecSQL","x":1160,"y":420,"wires":[[]]},{"id":"60d4f788.2f0518","type":"ui_group","z":"","name":"Assembly Lines","tab":"3e7f6350.5b23cc","disp":true,"width":"6","collapse":false},{"id":"10353f56.f3abf1","type":"ui_group","z":"","name":"Assembly Lines ","tab":"3e7f6350.5b23cc","disp":true,"width":"6","collapse":false},{"id":"ee18ca73.bf61a8","type":"ui_group","z":"","name":"Assembly Lines ","tab":"3e7f6350.5b23cc","disp":true,"width":"6","collapse":false},{"id":"8766660e.a1b488","type":"sqlitedb","z":"","db":"/var/www/html/database/Status","mode":"RWC"},{"id":"3e7f6350.5b23cc","type":"ui_tab","z":"","name":"Chasis Lines","icon":"dashboard"}]

```

var outputs = ;

> sql = "INSERT INTO Status (Device,Value)" +  
> "VALUES ('Temperature', "+ msg.payload +")";  
> outputs.push({topic:sql});  
> sql = "INSERT INTO Status (Device,Value)" +  
> "VALUES ('Humidity', "+ msg.humidity +")";  
> outputs.push({topic:sql});  
> return msg;

 ![Untitled](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/6/65ffb918b8a7b7ee42f72737000291f0d1e59a0e.png)

---

<div class="post-metadata">

**Author:** ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)\
**Post date:** [13 November 2018 11:28 UTC](https://discourse.nodered.org/t/saving-data-in-db-at-sqlite-function-help/4789/17 "2018-11-13T11:28:45Z")

</div>

When sharing code please use the ``` around the code as you have done with the flow, not blockquote.

You code is building up a `outputs` array, but then does nothing with it and returns `msg`. I assume that's isn't what you mean to do? Given it looks like you want to send two messages from the node, you'd want to end it with `return [outputs]` so that each message in the outputs array is sent.

---

<div class="post-metadata">

**Author:** ![wtrk](https://avatars.discourse-cdn.com/v4/letter/w/97f17d/32.png) [@wtrk](https://discourse.nodered.org/u/wtrk)\
**Post date:** [13 November 2018 12:06 UTC](https://discourse.nodered.org/t/saving-data-in-db-at-sqlite-function-help/4789/18 "2018-11-13T12:06:47Z")

</div>

> [@knolleary](#):
>
> When sharing code please use the ``` around the code as you have done with the flow, not blockquote.
> 
> You code is building up a `outputs` array, but then does nothing with it and returns `msg`. I assume that's isn't what you mean to do? Given it looks like you want to send two messages from the node, you'd want to end it with `return [outputs]` so that each message in the outputs array is sent.

Ok, thanks for your advice. If possible can you edit my function code please ?  
I just want to send data from DHT11 to Litesql db. How can I do this ?

---

<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:** [13 November 2018 12:15 UTC](https://discourse.nodered.org/t/saving-data-in-db-at-sqlite-function-help/4789/19 "2018-11-13T12:15:29Z")

</div>

Did you even try Nick's advice?

---

<div class="post-metadata">

**Author:** ![knolleary](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/knolleary/32/3_2.png) [@knolleary](https://discourse.nodered.org/u/knolleary)\
**Post date:** [13 November 2018 12:38 UTC](https://discourse.nodered.org/t/saving-data-in-db-at-sqlite-function-help/4789/20 "2018-11-13T12:38:27Z")

</div>

> [@wtrk](#):
>
> If possible can you edit my function code please ?

I gave you the one line change to make in my reply. Please at least try it for yourself.

[Next page](https://discourse.nodered.org/t/saving-data-in-db-at-sqlite-function-help/4789.md?page=2)
