UNPKG

node-red-contrib-mssql-plus

Version:

A node-red node to execute queries, stored procedures and bulk inserts in Microsoft SQL Server and Azure Databases SQL2000 ~ SQL2022

740 lines 20.9 kB
[ { "id": "adf228cf.156ef8", "type": "inject", "z": "403d67ed1c8bce92", "name": "", "props": [ { "p": "payload" }, { "p": "topic", "vt": "str" } ], "repeat": "", "crontab": "", "once": false, "onceDelay": 0.1, "topic": "rows", "payload": "1000", "payloadType": "num", "x": 560, "y": 1220, "wires": [ [ "d136ada3.dc6ca" ] ] }, { "id": "d136ada3.dc6ca", "type": "function", "z": "403d67ed1c8bce92", "name": "generate data", "func": "// Table fields...\n// IP, Name, Timestamp, Param_Name, Param_Value\n\nlet IP = \"1.2.3.4\";\nlet Name = \"fake_device\";\nlet now = (new Date()).toISOString(); //generate a timestamp\nmsg.bulk_data_to_insert = []; //the msg property we will use to pass the data array to the MSSQL node\n\n//generate fake data rows of data in the following format...\n/*\n[\n [col1, col2, coln... ], //row 1\n [col1, col2, coln... ], //row 2\n [col1, col2, coln... ], //row n\n]\n*/\nif (msg.topic == \"rows\") {\n for (let x = 1; x <= msg.payload; x++) {\n msg.bulk_data_to_insert.push([\n IP, Name, now, `P${x + 1000}`, Math.random()\n ]);\n }\n} else {\n for (let x = 1; x <= msg.payload; x++) {\n msg.bulk_data_to_insert.push({\n IP: IP, \n Name: Name, \n Timestamp: now, \n Param_Name: `P${x + 1000}`,\n Param_Value: Math.random()\n });\n }\n}\n\nreturn msg;", "outputs": 1, "noerr": 0, "initialize": "", "finalize": "", "x": 780, "y": 1220, "wires": [ [ "cb72c16f.a181e", "9913e507.15f5c8" ] ] }, { "id": "cb72c16f.a181e", "type": "debug", "z": "403d67ed1c8bce92", "name": "Bulk Data to insert", "active": true, "tosidebar": true, "console": false, "tostatus": false, "complete": "bulk_data_to_insert", "targetType": "msg", "statusVal": "", "statusType": "auto", "x": 1130, "y": 1220, "wires": [] }, { "id": "9913e507.15f5c8", "type": "MSSQL", "z": "403d67ed1c8bce92", "mssqlCN": "8d9d212a.cea03", "name": "bulk insert -> demo_device_parameters_table", "outField": "payload", "returnType": "0", "throwErrors": 1, "query": "demo_device_parameters_table", "modeOpt": "", "modeOptType": "bulk", "queryOpt": "", "queryOptType": "editor", "paramsOpt": "", "paramsOptType": "editor", "rows": "bulk_data_to_insert", "rowsType": "msg", "parseMustache": false, "params": [ { "output": false, "name": "IP", "type": "NVarChar(200)", "valueType": "msg", "value": "payload", "options": { "nullable": true, "primary": false, "identity": false, "readOnly": false } }, { "output": false, "name": "Name", "type": "NVarChar(200)", "valueType": "num", "value": "0", "options": { "nullable": true, "primary": false, "identity": false, "readOnly": false } }, { "output": false, "name": "Timestamp", "type": "NVarChar(200)", "valueType": "num", "value": "0", "options": { "nullable": true, "primary": false, "identity": false, "readOnly": false } }, { "output": false, "name": "Param_Name", "type": "NVarChar(200)", "valueType": "num", "value": "0", "options": { "nullable": true, "primary": false, "identity": false, "readOnly": false } }, { "output": false, "name": "Param_Value", "type": "Float", "valueType": "num", "value": "0", "options": { "nullable": true, "primary": false, "identity": false, "readOnly": false } } ], "x": 920, "y": 1260, "wires": [ [ "1af45092.0fc77f" ] ] }, { "id": "1af45092.0fc77f", "type": "debug", "z": "403d67ed1c8bce92", "name": "Bulk Insert Result", "active": true, "tosidebar": true, "console": false, "tostatus": false, "complete": "payload", "targetType": "msg", "statusVal": "", "statusType": "auto", "x": 1130, "y": 1300, "wires": [] }, { "id": "3344173.094bde8", "type": "inject", "z": "403d67ed1c8bce92", "name": "", "props": [ { "p": "payload" }, { "p": "topic", "vt": "str" } ], "repeat": "", "crontab": "", "once": false, "onceDelay": 0.1, "topic": "rows", "payload": "10000", "payloadType": "num", "x": 570, "y": 1260, "wires": [ [ "d136ada3.dc6ca" ] ] }, { "id": "378a591d.b0ce76", "type": "inject", "z": "403d67ed1c8bce92", "name": "", "props": [ { "p": "payload" }, { "p": "topic", "vt": "str" } ], "repeat": "", "crontab": "", "once": false, "onceDelay": 0.1, "topic": "objects", "payload": "2000", "payloadType": "num", "x": 570, "y": 1300, "wires": [ [ "d136ada3.dc6ca" ] ] }, { "id": "4de6a61.bbf2458", "type": "MSSQL", "z": "403d67ed1c8bce92", "mssqlCN": "8d9d212a.cea03", "name": "Create demo_device_parameters_table", "outField": "payload", "returnType": "1", "throwErrors": 1, "query": "\r\nSET ANSI_NULLS ON\r\nSET QUOTED_IDENTIFIER ON\r\n\r\nCREATE TABLE [dbo].[demo_device_parameters_table](\r\n [ID] int not null identity(1,1),\t\r\n [IP] nvarchar(200) NULL,\r\n [Name] nvarchar(200) NULL,\r\n [Timestamp] nvarchar(200) NULL,\r\n [Param_Name] nvarchar(200) NULL,\r\n [Param_Value] float NULL\r\n) ON [PRIMARY]", "modeOpt": "", "modeOptType": "query", "queryOpt": "", "queryOptType": "editor", "paramsOpt": "", "paramsOptType": "none", "rows": "rows", "rowsType": "msg", "parseMustache": false, "params": [], "x": 800, "y": 1140, "wires": [ [ "c173bd82.e50f7" ] ] }, { "id": "4fe9670.507ad98", "type": "inject", "z": "403d67ed1c8bce92", "name": "Start", "props": [ { "p": "payload" }, { "p": "topic", "vt": "str" } ], "repeat": "", "crontab": "", "once": false, "onceDelay": 0.1, "topic": "", "payload": "", "payloadType": "str", "x": 550, "y": 1140, "wires": [ [ "4de6a61.bbf2458" ] ] }, { "id": "c173bd82.e50f7", "type": "debug", "z": "403d67ed1c8bce92", "name": "Table creation", "active": true, "tosidebar": true, "console": false, "tostatus": false, "complete": "true", "targetType": "full", "statusVal": "", "statusType": "auto", "x": 1120, "y": 1140, "wires": [] }, { "id": "6347054e.31519c", "type": "comment", "z": "403d67ed1c8bce92", "name": "1. Open the MSSQL node and set up the connection to your SQL Server", "info": "", "x": 730, "y": 920, "wires": [] }, { "id": "47b777cb.bf8488", "type": "comment", "z": "403d67ed1c8bce92", "name": "2. Click the \"Start\" Inject to create the table", "info": "", "x": 640, "y": 960, "wires": [] }, { "id": "ee216795.b3ed88", "type": "comment", "z": "403d67ed1c8bce92", "name": "3. Click any of the \"rows: xxxx\" Injects to perform a Bulk Insert", "info": "", "x": 700, "y": 1000, "wires": [] }, { "id": "f8125aa3.1029b8", "type": "comment", "z": "403d67ed1c8bce92", "name": "4. Click \"Get Data\" Inject to select data from the table", "info": "", "x": 670, "y": 1040, "wires": [] }, { "id": "29d96080.aad37", "type": "inject", "z": "403d67ed1c8bce92", "name": "Get top 1000 with ID >= 200", "props": [ { "p": "payload" }, { "p": "topic", "vt": "str" } ], "repeat": "", "crontab": "", "once": false, "onceDelay": 0.1, "topic": "1000", "payload": "200", "payloadType": "num", "x": 620, "y": 1500, "wires": [ [ "9e3efaa0.4d1258" ] ] }, { "id": "9e3efaa0.4d1258", "type": "MSSQL", "z": "403d67ed1c8bce92", "mssqlCN": "8d9d212a.cea03", "name": "Select Data", "outField": "payload", "returnType": "0", "throwErrors": 1, "query": "PRINT 'Selecting TOP {{{topic}}} from demo_device_parameters_table'\r\nPRINT 'Where ID if > or = to '\r\nPRINT @ID\r\nSELECT TOP {{{topic}}} * \r\nFROM [dbo].[demo_device_parameters_table]\r\nWHERE ID >= @ID\r\nPRINT @@ROWCOUNT\r\n\r\n--Print info will appear in msg.sqlInfo", "modeOpt": "", "modeOptType": "query", "queryOpt": "", "queryOptType": "editor", "paramsOpt": "", "paramsOptType": "editor", "rows": "rows", "rowsType": "msg", "parseMustache": true, "params": [ { "output": false, "name": "ID", "type": "int", "valueType": "msg", "value": "payload", "options": { "nullable": true, "primary": false, "identity": false, "readOnly": false } } ], "x": 870, "y": 1520, "wires": [ [ "6f2eedb2.232a14" ] ] }, { "id": "6f2eedb2.232a14", "type": "debug", "z": "403d67ed1c8bce92", "name": "Selected Data", "active": true, "tosidebar": true, "console": false, "tostatus": false, "complete": "true", "targetType": "full", "statusVal": "", "statusType": "auto", "x": 1120, "y": 1520, "wires": [] }, { "id": "50f35944.757a98", "type": "inject", "z": "403d67ed1c8bce92", "name": "Clean up", "props": [ { "p": "payload" }, { "p": "topic", "vt": "str" } ], "repeat": "", "crontab": "", "once": false, "onceDelay": 0.1, "topic": "", "payload": "", "payloadType": "str", "x": 560, "y": 1620, "wires": [ [ "5d35875.1813978" ] ] }, { "id": "5d35875.1813978", "type": "MSSQL", "z": "403d67ed1c8bce92", "mssqlCN": "8d9d212a.cea03", "name": "Drop demo_device_parameters_table", "outField": "payload", "returnType": "1", "throwErrors": 1, "query": "\r\nDROP TABLE [dbo].[demo_device_parameters_table]\r\n", "modeOpt": "", "modeOptType": "query", "queryOpt": "", "queryOptType": "editor", "paramsOpt": "", "paramsOptType": "none", "rows": "rows", "rowsType": "msg", "parseMustache": true, "params": [], "x": 810, "y": 1620, "wires": [ [ "171cac85.61f193" ] ] }, { "id": "171cac85.61f193", "type": "debug", "z": "403d67ed1c8bce92", "name": "Clean up result", "active": true, "tosidebar": true, "console": false, "tostatus": false, "complete": "true", "targetType": "full", "statusVal": "", "statusType": "auto", "x": 1120, "y": 1620, "wires": [] }, { "id": "773638cc.7c5478", "type": "inject", "z": "403d67ed1c8bce92", "name": "Get top 50 with ID >= 1000", "props": [ { "p": "payload" }, { "p": "topic", "vt": "str" } ], "repeat": "", "crontab": "", "once": false, "onceDelay": 0.1, "topic": "50", "payload": "1000", "payloadType": "num", "x": 610, "y": 1540, "wires": [ [ "9e3efaa0.4d1258" ] ] }, { "id": "100cb0e1.3c1c8f", "type": "comment", "z": "403d67ed1c8bce92", "name": "5. Click \"Clean up\" Inject to drop the table", "info": "", "x": 640, "y": 1080, "wires": [] }, { "id": "34b7b9848b9446ea", "type": "inject", "z": "403d67ed1c8bce92", "name": "", "props": [ { "p": "payload" }, { "p": "topic", "vt": "str" } ], "repeat": "", "crontab": "", "once": false, "onceDelay": 0.1, "topic": "rows", "payload": "1000", "payloadType": "num", "x": 560, "y": 1360, "wires": [ [ "ab27ed3bf3bb6cb0" ] ] }, { "id": "ab27ed3bf3bb6cb0", "type": "function", "z": "403d67ed1c8bce92", "name": "generate data and params", "func": "// Table fields...\n// IP, Name, Timestamp, Param_Name, Param_Value\n\nlet IP = \"1.2.3.4\";\nlet Name = \"fake_device\";\nlet now = (new Date()).toISOString(); //generate a timestamp\nmsg.bulk_data_to_insert = []; //the msg property we will use to pass the data array to the MSSQL node\n\n//generate fake data rows of data in the following format...\n/*\n[\n [col1, col2, coln... ], //row 1\n [col1, col2, coln... ], //row 2\n [col1, col2, coln... ], //row n\n]\n*/\nif (msg.topic == \"rows\") {\n for (let x = 1; x <= msg.payload; x++) {\n msg.bulk_data_to_insert.push([\n IP, Name, now, `P${x + 1000}`, Math.random()\n ]);\n }\n} else {\n for (let x = 1; x <= msg.payload; x++) {\n msg.bulk_data_to_insert.push({\n IP: IP, \n Name: Name, \n Timestamp: now, \n Param_Name: `P${x + 1000}`,\n Param_Value: Math.random()\n });\n }\n}\n\nmsg.queryParams = [ \n { output: false, name: \"IP\", type: \"Nvarchar(200)\", options: { nullable: true } },\n { output: false, name: \"Name\", type: \"Nvarchar(200)\", options: { nullable: true } },\n { output: false, name: \"Timestamp\", type: \"Nvarchar(200)\", options: { nullable: true } },\n { output: false, name: \"Param_Name\", type: \"Nvarchar(200)\", options: { nullable: true } },\n { output: false, name: \"Param_Value\", type: \"float\", options: { nullable: true } }\n]\n\nreturn msg;", "outputs": 1, "timeout": "", "noerr": 0, "initialize": "", "finalize": "", "libs": [], "x": 820, "y": 1360, "wires": [ [ "ebd9f8405d64540c", "fb8fcf7db017e8c4" ] ] }, { "id": "750b93555a38e08b", "type": "inject", "z": "403d67ed1c8bce92", "name": "", "props": [ { "p": "payload" }, { "p": "topic", "vt": "str" } ], "repeat": "", "crontab": "", "once": false, "onceDelay": 0.1, "topic": "rows", "payload": "10000", "payloadType": "num", "x": 570, "y": 1400, "wires": [ [ "ab27ed3bf3bb6cb0" ] ] }, { "id": "29aee9ba8595af32", "type": "inject", "z": "403d67ed1c8bce92", "name": "", "props": [ { "p": "payload" }, { "p": "topic", "vt": "str" } ], "repeat": "", "crontab": "", "once": false, "onceDelay": 0.1, "topic": "objects", "payload": "2000", "payloadType": "num", "x": 570, "y": 1440, "wires": [ [ "ab27ed3bf3bb6cb0" ] ] }, { "id": "ebd9f8405d64540c", "type": "debug", "z": "403d67ed1c8bce92", "name": "Bulk Data to insert", "active": true, "tosidebar": true, "console": false, "tostatus": false, "complete": "bulk_data_to_insert", "targetType": "msg", "statusVal": "", "statusType": "auto", "x": 1130, "y": 1360, "wires": [] }, { "id": "fb8fcf7db017e8c4", "type": "MSSQL", "z": "403d67ed1c8bce92", "mssqlCN": "8d9d212a.cea03", "name": "bulk insert with params -> demo_device_parameters_table", "outField": "payload", "returnType": "0", "throwErrors": 1, "query": "demo_device_parameters_table", "modeOpt": "", "modeOptType": "bulk", "queryOpt": "", "queryOptType": "editor", "paramsOpt": "queryParams", "paramsOptType": "msg", "rows": "bulk_data_to_insert", "rowsType": "msg", "parseMustache": false, "params": [], "x": 960, "y": 1400, "wires": [ [ "cc6648dcfaba3bbc" ] ] }, { "id": "cc6648dcfaba3bbc", "type": "debug", "z": "403d67ed1c8bce92", "name": "Bulk Insert Result", "active": true, "tosidebar": true, "console": false, "tostatus": false, "complete": "payload", "targetType": "msg", "statusVal": "", "statusType": "auto", "x": 1130, "y": 1440, "wires": [] }, { "id": "8d9d212a.cea03", "type": "MSSQL-CN", "tdsVersion": "7_4", "name": "My SQL Server connection", "server": "172.17.1.2", "port": "1433", "encyption": true, "trustServerCertificate": true, "database": "testdb", "useUTC": true, "connectTimeout": "15000", "requestTimeout": "15000", "cancelTimeout": "5000", "pool": "5", "parseJSON": false, "enableArithAbort": true, "readOnlyIntent": false } ]