Skip to content

Commit

Permalink
Merge pull request #83 from belgianbeer/belgianbeer/bugfix-bulkinsert
Browse files Browse the repository at this point in the history
Bug fix on demo of bulk insert. see Issue #79
  • Loading branch information
Steve-Mcl authored Nov 25, 2023
2 parents b82522d + b4721ef commit 64f78f4
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion examples/Bulk demo.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
[{"id":"adf228cf.156ef8","type":"inject","z":"30e2e9e0.eeaab6","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"rows","payload":"1000","payloadType":"num","x":460,"y":2900,"wires":[["d136ada3.dc6ca"]]},{"id":"d136ada3.dc6ca","type":"function","z":"30e2e9e0.eeaab6","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":680,"y":2900,"wires":[["cb72c16f.a181e","9913e507.15f5c8"]]},{"id":"cb72c16f.a181e","type":"debug","z":"30e2e9e0.eeaab6","name":"Bulk Data to insert","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"bulk_data_to_insert","targetType":"msg","statusVal":"","statusType":"auto","x":990,"y":2900,"wires":[]},{"id":"9913e507.15f5c8","type":"MSSQL","z":"30e2e9e0.eeaab6","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","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":"NVarChar(200)","valueType":"num","value":"0","options":{"nullable":true,"primary":false,"identity":false,"readOnly":false}}],"x":820,"y":2940,"wires":[["1af45092.0fc77f"]]},{"id":"1af45092.0fc77f","type":"debug","z":"30e2e9e0.eeaab6","name":"Bulk Insert Result","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":990,"y":2980,"wires":[]},{"id":"3344173.094bde8","type":"inject","z":"30e2e9e0.eeaab6","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"rows","payload":"10000","payloadType":"num","x":470,"y":2940,"wires":[["d136ada3.dc6ca"]]},{"id":"378a591d.b0ce76","type":"inject","z":"30e2e9e0.eeaab6","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"objects","payload":"2000","payloadType":"num","x":470,"y":2980,"wires":[["d136ada3.dc6ca"]]},{"id":"4de6a61.bbf2458","type":"MSSQL","z":"30e2e9e0.eeaab6","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","params":[],"x":700,"y":2820,"wires":[["c173bd82.e50f7"]]},{"id":"4fe9670.507ad98","type":"inject","z":"30e2e9e0.eeaab6","name":"Start","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"str","x":450,"y":2820,"wires":[["4de6a61.bbf2458"]]},{"id":"c173bd82.e50f7","type":"debug","z":"30e2e9e0.eeaab6","name":"Table creation","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":980,"y":2820,"wires":[]},{"id":"6347054e.31519c","type":"comment","z":"30e2e9e0.eeaab6","name":"1. Open the MSSQL node and set up the connection to your SQL Server","info":"","x":630,"y":2600,"wires":[]},{"id":"47b777cb.bf8488","type":"comment","z":"30e2e9e0.eeaab6","name":"2. Click the \"Start\" Inject to create the table","info":"","x":540,"y":2640,"wires":[]},{"id":"ee216795.b3ed88","type":"comment","z":"30e2e9e0.eeaab6","name":"3. Click any of the \"rows: xxxx\" Injects to perform a Bulk Insert","info":"","x":600,"y":2680,"wires":[]},{"id":"f8125aa3.1029b8","type":"comment","z":"30e2e9e0.eeaab6","name":"4. Click \"Get Data\" Inject to select data from the table","info":"","x":570,"y":2720,"wires":[]},{"id":"29d96080.aad37","type":"inject","z":"30e2e9e0.eeaab6","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":520,"y":3060,"wires":[["9e3efaa0.4d1258"]]},{"id":"9e3efaa0.4d1258","type":"MSSQL","z":"30e2e9e0.eeaab6","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","params":[{"output":false,"name":"ID","type":"int","valueType":"msg","value":"payload"}],"x":770,"y":3080,"wires":[["6f2eedb2.232a14"]]},{"id":"6f2eedb2.232a14","type":"debug","z":"30e2e9e0.eeaab6","name":"Selected Data","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":980,"y":3080,"wires":[]},{"id":"50f35944.757a98","type":"inject","z":"30e2e9e0.eeaab6","name":"Clean up","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"str","x":460,"y":3180,"wires":[["5d35875.1813978"]]},{"id":"5d35875.1813978","type":"MSSQL","z":"30e2e9e0.eeaab6","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","params":[],"x":710,"y":3180,"wires":[["171cac85.61f193"]]},{"id":"171cac85.61f193","type":"debug","z":"30e2e9e0.eeaab6","name":"Clean up result","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":980,"y":3180,"wires":[]},{"id":"773638cc.7c5478","type":"inject","z":"30e2e9e0.eeaab6","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":510,"y":3100,"wires":[["9e3efaa0.4d1258"]]},{"id":"100cb0e1.3c1c8f","type":"comment","z":"30e2e9e0.eeaab6","name":"5. Click \"Clean up\" Inject to drop the table","info":"","x":540,"y":2760,"wires":[]},{"id":"8d9d212a.cea03","type":"MSSQL-CN","tdsVersion":"7_4","name":"My SQL Server connection","server":"192.168.1.38","port":"1433","encyption":false,"trustServerCertificate":true,"database":"testdb","useUTC":true,"connectTimeout":"15000","requestTimeout":"15000","cancelTimeout":"5000","pool":"5","parseJSON":false,"enableArithAbort":true}]
[{"id":"adf228cf.156ef8","type":"inject","z":"30e2e9e0.eeaab6","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"rows","payload":"1000","payloadType":"num","x":460,"y":2900,"wires":[["d136ada3.dc6ca"]]},{"id":"d136ada3.dc6ca","type":"function","z":"30e2e9e0.eeaab6","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":680,"y":2900,"wires":[["cb72c16f.a181e","9913e507.15f5c8"]]},{"id":"cb72c16f.a181e","type":"debug","z":"30e2e9e0.eeaab6","name":"Bulk Data to insert","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"bulk_data_to_insert","targetType":"msg","statusVal":"","statusType":"auto","x":990,"y":2900,"wires":[]},{"id":"9913e507.15f5c8","type":"MSSQL","z":"30e2e9e0.eeaab6","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","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":820,"y":2940,"wires":[["1af45092.0fc77f"]]},{"id":"1af45092.0fc77f","type":"debug","z":"30e2e9e0.eeaab6","name":"Bulk Insert Result","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","statusVal":"","statusType":"auto","x":990,"y":2980,"wires":[]},{"id":"3344173.094bde8","type":"inject","z":"30e2e9e0.eeaab6","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"rows","payload":"10000","payloadType":"num","x":470,"y":2940,"wires":[["d136ada3.dc6ca"]]},{"id":"378a591d.b0ce76","type":"inject","z":"30e2e9e0.eeaab6","name":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"objects","payload":"2000","payloadType":"num","x":470,"y":2980,"wires":[["d136ada3.dc6ca"]]},{"id":"4de6a61.bbf2458","type":"MSSQL","z":"30e2e9e0.eeaab6","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","params":[],"x":700,"y":2820,"wires":[["c173bd82.e50f7"]]},{"id":"4fe9670.507ad98","type":"inject","z":"30e2e9e0.eeaab6","name":"Start","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"str","x":450,"y":2820,"wires":[["4de6a61.bbf2458"]]},{"id":"c173bd82.e50f7","type":"debug","z":"30e2e9e0.eeaab6","name":"Table creation","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":980,"y":2820,"wires":[]},{"id":"6347054e.31519c","type":"comment","z":"30e2e9e0.eeaab6","name":"1. Open the MSSQL node and set up the connection to your SQL Server","info":"","x":630,"y":2600,"wires":[]},{"id":"47b777cb.bf8488","type":"comment","z":"30e2e9e0.eeaab6","name":"2. Click the \"Start\" Inject to create the table","info":"","x":540,"y":2640,"wires":[]},{"id":"ee216795.b3ed88","type":"comment","z":"30e2e9e0.eeaab6","name":"3. Click any of the \"rows: xxxx\" Injects to perform a Bulk Insert","info":"","x":600,"y":2680,"wires":[]},{"id":"f8125aa3.1029b8","type":"comment","z":"30e2e9e0.eeaab6","name":"4. Click \"Get Data\" Inject to select data from the table","info":"","x":570,"y":2720,"wires":[]},{"id":"29d96080.aad37","type":"inject","z":"30e2e9e0.eeaab6","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":520,"y":3060,"wires":[["9e3efaa0.4d1258"]]},{"id":"9e3efaa0.4d1258","type":"MSSQL","z":"30e2e9e0.eeaab6","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","params":[{"output":false,"name":"ID","type":"int","valueType":"msg","value":"payload"}],"x":770,"y":3080,"wires":[["6f2eedb2.232a14"]]},{"id":"6f2eedb2.232a14","type":"debug","z":"30e2e9e0.eeaab6","name":"Selected Data","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":980,"y":3080,"wires":[]},{"id":"50f35944.757a98","type":"inject","z":"30e2e9e0.eeaab6","name":"Clean up","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"","payloadType":"str","x":460,"y":3180,"wires":[["5d35875.1813978"]]},{"id":"5d35875.1813978","type":"MSSQL","z":"30e2e9e0.eeaab6","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","params":[],"x":710,"y":3180,"wires":[["171cac85.61f193"]]},{"id":"171cac85.61f193","type":"debug","z":"30e2e9e0.eeaab6","name":"Clean up result","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":980,"y":3180,"wires":[]},{"id":"773638cc.7c5478","type":"inject","z":"30e2e9e0.eeaab6","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":510,"y":3100,"wires":[["9e3efaa0.4d1258"]]},{"id":"100cb0e1.3c1c8f","type":"comment","z":"30e2e9e0.eeaab6","name":"5. Click \"Clean up\" Inject to drop the table","info":"","x":540,"y":2760,"wires":[]},{"id":"8d9d212a.cea03","type":"MSSQL-CN","tdsVersion":"7_4","name":"My SQL Server connection","server":"192.168.1.38","port":"1433","encyption":false,"trustServerCertificate":true,"database":"testdb","useUTC":true,"connectTimeout":"15000","requestTimeout":"15000","cancelTimeout":"5000","pool":"5","parseJSON":false,"enableArithAbort":true}]

0 comments on commit 64f78f4

Please sign in to comment.