Nodered and SQLite Integration - Error

Good Afternoon!! Now, I currently developed nodered data send to SQLite DB. Here table is created but no data is stored in particular DB. Can you able to check my node flow. I updated below. I shared some details for your reference.

My Node Flow :

      [
{
    "id": "46d14a4e416a8d6a",
    "type": "debug",
    "z": "7d551c48106025c7",
    "name": "Debug Output",
    "active": true,
    "tosidebar": true,
    "console": false,
    "tostatus": false,
    "complete": "true",
    "targetType": "full",
    "x": 880,
    "y": 200,
    "wires": []
},
{
    "id": "2998ba3a5b05beaa",
    "type": "sqlite",
    "z": "7d551c48106025c7",
    "mydb": "database1",
    "sqlquery": "msg.topic",
    "sql": "",
    "name": "SQLite Node",
    "x": 690,
    "y": 200,
    "wires": [
        [
            "46d14a4e416a8d6a"
        ]
    ]
},
{
    "id": "1965d63de4ce50a6",
    "type": "function",
    "z": "7d551c48106025c7",
    "name": "Prepare SQL Query",
    "func": "//\n\nmsg.topic = \"INSERT INTO data (timestamp, value) VALUES (?, ?)\";\nmsg.params = [msg.payload.timestamp, msg.payload.value];\nreturn msg;\n",
    "outputs": 1,
    "noerr": 0,
    "initialize": "",
    "finalize": "",
    "libs": [],
    "x": 480,
    "y": 200,
    "wires": [
        [
            "2998ba3a5b05beaa"
        ]
    ]
},
{
    "id": "3adeb6a4606db0b1",
    "type": "inject",
    "z": "7d551c48106025c7",
    "name": "Inject Data",
    "props": [
        {
            "p": "payload"
        },
        {
            "p": "topic",
            "vt": "str"
        }
    ],
    "repeat": "",
    "crontab": "",
    "once": false,
    "onceDelay": 0.1,
    "topic": "",
    "payload": "{\"timestamp\": \"2025-01-10T15:45:00\",    \"value\": 123.45}",
    "payloadType": "json",
    "x": 280,
    "y": 200,
    "wires": [
        [
            "1965d63de4ce50a6"
        ]
    ]
},
{
    "id": "database1",
    "type": "sqlitedb",
    "db": "C:/Users/User/Desktop/mydata.db",
    "mode": "RWC"
}

]

I need solution for this. Thank you....

Also, before sqlite node msg.payload debug output image

After sqlite node msg.payload debug output image

Did you actually create the db on the filing system? I think that SQLite defaults to an in-memory db, you need to actually create a db as a file.

Before you start doing inserts, you must first define the table.
You can create the table definition and send it to the sqlite node to create the table then start insert or retrieving data.

Here is an example flow using a template node to build a table, insert data and run a select:

[{"id":"771a4816.0c4cd","type":"inject","z":"b54cfc20.fecb38","name":"Create Table","repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":130,"y":80,"wires":[["1f7f15b5.e2d6aa"]]},{"id":"1f7f15b5.e2d6aa","type":"template","z":"b54cfc20.fecb38","name":"","field":"topic","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"CREATE TABLE hvac4(\n    ID INTEGER PRIMARY KEY AUTOINCREMENT, \n    UTC INTEGER,\n    DateTime TEXT,\n    hp NUMERIC, \n    lp NUMERIC \n)","output":"str","x":320,"y":80,"wires":[["25b23f04.053a1"]]},{"id":"25b23f04.053a1","type":"sqlite","z":"b54cfc20.fecb38","mydb":"b48607bf.623f88","sqlquery":"msg.topic","sql":"","name":"Sqlite","x":510,"y":140,"wires":[["16c71ea.b668961"]]},{"id":"56c189c6.5cab38","type":"inject","z":"b54cfc20.fecb38","name":"Insert multi rows","repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":140,"y":140,"wires":[["b996e9de.cd54c8"]]},{"id":"16c71ea.b668961","type":"debug","z":"b54cfc20.fecb38","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","x":650,"y":140,"wires":[]},{"id":"b996e9de.cd54c8","type":"template","z":"b54cfc20.fecb38","name":"","field":"topic","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"INSERT INTO hvac4(\n    ID,\n    UTC,\n    DateTime,\n    hp, \n    lp  \n    )\nVALUES\n    (1695,1583209921955,\"2020/03/02T20:32:01\",77.1,74.2),\n(1694,1583207096121,\"2020/03/02T19:44:56\",78.2,76.6),\n(1693,1583206453163,\"2020/03/02T19:34:13\",77.9,76.4),\n(1692,1583164232433,\"2020/03/02T07:50:32\",74,78.1),\n(1691,1583163932418,\"2020/03/02T07:45:32\",73.3,75.2),\n(1690,1583163632415,\"2020/03/02T07:40:32\",73.1,73.7),\n(1689,1583163332419,\"2020/03/02T07:35:32\",73.1,72),\n(1688,1583163032423,\"2020/03/02T07:30:32\",73,72.1),\n(1687,1583162732413,\"2020/03/02T07:25:32\",73.4,72.7),\n(1686,1583162432401,\"2020/03/02T07:20:32\",73.5,73.3),\n(1685,1583162132391,\"2020/03/02T07:15:32\",72.6,71),\n(1684,1583161832396,\"2020/03/02T07:10:32\",72.7,71.2),\n(1683,1583161532392,\"2020/03/02T07:05:32\",72.9,71.8),\n(1682,1583161232394,\"2020/03/02T07:00:32\",72.9,72.2),\n(1681,1583160932396,\"2020/03/02T06:55:32\",72.9,72),\n(1680,1583160632397,\"2020/03/02T06:50:32\",72.9,71.6),\n(1679,1583160332382,\"2020/03/02T06:45:32\",73.3,72.1),\n(1678,1583160032392,\"2020/03/02T06:40:32\",73.2,71.9),\n(1677,1583159732387,\"2020/03/02T06:35:32\",72.6,70.2),\n(1676,1583159432365,\"2020/03/02T06:30:32\",72.7,70.3),\n(1675,1583159132367,\"2020/03/02T06:25:32\",72.8,70.4),\n(1674,1583158832363,\"2020/03/02T06:20:32\",73,70.9),\n(1673,1583158532364,\"2020/03/02T06:15:32\",73.4,71.7),\n(1672,1583158232344,\"2020/03/02T06:10:32\",73.7,72.5),\n(1671,1583157932355,\"2020/03/02T06:05:32\",72.8,70.2),\n(1672,1582887743604,\"2020/02/28T03:02:23\",72.9,69.6)\n","output":"str","x":320,"y":140,"wires":[["25b23f04.053a1"]]},{"id":"5959dc0c.ad3044","type":"inject","z":"b54cfc20.fecb38","name":"select count","repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":130,"y":200,"wires":[["9bd539da.7d961"]]},{"id":"9bd539da.7d961","type":"template","z":"b54cfc20.fecb38","name":"","field":"topic","fieldType":"msg","format":"handlebars","syntax":"mustache","template":"SELECT COUNT(*) from hvac4","output":"str","x":320,"y":200,"wires":[["25b23f04.053a1"]]},{"id":"b48607bf.623f88","type":"sqlitedb","db":"/Users/Paul/databases/hvac4.db","mode":"RWC"}]

Above code was working fine, now I want to get the data from S7 node (PLC Live Data) and keep store to SQLite db. I have more no of variables like Temperature, RH, Intensity, Weather station values etc. Each 10 sec once values are stored in SQLite db. Kindly suggest the flow method. Thank You!!

If you want to add new columns to your sqlite database, you will need to use the ALTER command. see SQLite ALTER TABLE & How To Overcome Its Limitations

If that is not what you want to do, you will need to explain what you need in more detail.

1 Like

Good afternoon!! SQLite almost working fine for further any clarification I will connect you. Also I need to update SQL server process. Same PLC data will stored to SQL databases please kindly support for installation of server and data will stored to DB. If you have sample project update and guide me. Thank you,

Do you mean MS SQL Server? If so then I believe the recommended node to use is node-red-contrib-mssql-plus.

Yes, MS Sql. Ok I will move to "mssql plus" . Why You recommend "mssql plus"?

This is why: Mssql not sending data to database using mustache format - #4 by Steve-Mcl

While installing "mssql plus" node I got some error log. Error Log :


Kindly resolve this.

The answer is right there on your screenshot

image

You are running OLD (unsupported/end of life Node v16.20.1) and this node requires at LEAST Node v18.x

I recommend you upgrade to Node V20 LTS.

Right now I installed V20....


Then I was installed "mssql plus" node. Please updated demo project file.

I cannot. I dont have access to your database nor do i know what tables you have or what you are attempting to do. We are not here to create things for you. Please read the docs, read the help, search the forum.

Just out of interest, can you explain why you decided to switch from SQLite to MSSQL?

SQlite is good. Actually, We want updated data to power BI. So I will switch to sql server.

1 Like