mirror of
				https://github.com/node-red/node-red-nodes.git
				synced 2025-03-01 10:37:43 +00:00 
			
		
		
		
	Add bind capability to sqlite and mysql nodes
Thanks to Scott Penrose for the patch.
This commit is contained in:
		@@ -79,6 +79,7 @@
 | 
				
			|||||||
    <p>This node uses the <b>query</b> operation against the configured database. This does allow both INSERTS and DELETES.
 | 
					    <p>This node uses the <b>query</b> operation against the configured database. This does allow both INSERTS and DELETES.
 | 
				
			||||||
    By it's very nature it allows SQL injection... so <i>be careful out there...</i></p>
 | 
					    By it's very nature it allows SQL injection... so <i>be careful out there...</i></p>
 | 
				
			||||||
    <p><b>msg.topic</b> must hold the <i>query</i> for the database, and the result is returned in <b>msg.payload</b>.</p>
 | 
					    <p><b>msg.topic</b> must hold the <i>query</i> for the database, and the result is returned in <b>msg.payload</b>.</p>
 | 
				
			||||||
 | 
					    <p><b>msg.payload</b> can contain an array of values to bind to the topic.</p>
 | 
				
			||||||
    <p>Typically the returned payload will be an array of the result rows.</p>
 | 
					    <p>Typically the returned payload will be an array of the result rows.</p>
 | 
				
			||||||
    <p>If nothing is found for the key then <i>null</i> is returned,</p>
 | 
					    <p>If nothing is found for the key then <i>null</i> is returned,</p>
 | 
				
			||||||
    <p>The reconnect timeout in milliseconds can be changed by adding a line to <b>settings.js</b>
 | 
					    <p>The reconnect timeout in milliseconds can be changed by adding a line to <b>settings.js</b>
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -101,7 +101,8 @@ module.exports = function(RED) {
 | 
				
			|||||||
            node.on("input", function(msg) {
 | 
					            node.on("input", function(msg) {
 | 
				
			||||||
                if (typeof msg.topic === 'string') {
 | 
					                if (typeof msg.topic === 'string') {
 | 
				
			||||||
                    //console.log("query:",msg.topic);
 | 
					                    //console.log("query:",msg.topic);
 | 
				
			||||||
                    node.mydbConfig.connection.query(msg.topic, function(err, rows) {
 | 
					                    var bind = Array.isArray(msg.payload) ? msg.payload : [];
 | 
				
			||||||
 | 
					                    node.mydbConfig.connection.query(msg.topic, bind, function(err, rows) {
 | 
				
			||||||
                        if (err) { node.warn(err); }
 | 
					                        if (err) { node.warn(err); }
 | 
				
			||||||
                        else {
 | 
					                        else {
 | 
				
			||||||
                            msg.payload = rows;
 | 
					                            msg.payload = rows;
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,9 +1,9 @@
 | 
				
			|||||||
{
 | 
					{
 | 
				
			||||||
    "name"          : "node-red-node-mysql",
 | 
					    "name"          : "node-red-node-mysql",
 | 
				
			||||||
    "version"       : "0.0.4",
 | 
					    "version"       : "0.0.5",
 | 
				
			||||||
    "description"   : "A Node-RED node to read and write to a MySQL database",
 | 
					    "description"   : "A Node-RED node to read and write to a MySQL database",
 | 
				
			||||||
    "dependencies"  : {
 | 
					    "dependencies"  : {
 | 
				
			||||||
        "mysql"   : "2.3.*"
 | 
					        "mysql"   : "2.5.*"
 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
    "repository" : {
 | 
					    "repository" : {
 | 
				
			||||||
        "type":"git",
 | 
					        "type":"git",
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -1,9 +1,9 @@
 | 
				
			|||||||
{
 | 
					{
 | 
				
			||||||
    "name"          : "node-red-node-sqlite",
 | 
					    "name"          : "node-red-node-sqlite",
 | 
				
			||||||
    "version"       : "0.0.3",
 | 
					    "version"       : "0.0.4",
 | 
				
			||||||
    "description"   : "A sqlite node for Node-RED",
 | 
					    "description"   : "A sqlite node for Node-RED",
 | 
				
			||||||
    "dependencies"  : {
 | 
					    "dependencies"  : {
 | 
				
			||||||
        "sqlite3"   : "2.x"
 | 
					        "sqlite3"   : "3.0.*"
 | 
				
			||||||
    },
 | 
					    },
 | 
				
			||||||
    "repository" : {
 | 
					    "repository" : {
 | 
				
			||||||
        "type":"git",
 | 
					        "type":"git",
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -50,6 +50,7 @@
 | 
				
			|||||||
    <p>This node uses the <b>db.all</b> operation against the configured database. This does allow INSERTS, UPDATES and DELETES.
 | 
					    <p>This node uses the <b>db.all</b> operation against the configured database. This does allow INSERTS, UPDATES and DELETES.
 | 
				
			||||||
    By it's very nature it is SQL injection... so <i>be careful out there...</i></p>
 | 
					    By it's very nature it is SQL injection... so <i>be careful out there...</i></p>
 | 
				
			||||||
    <p><b>msg.topic</b> must hold the <i>query</i> for the database, and the result is returned in <b>msg.payload</b>.</p>
 | 
					    <p><b>msg.topic</b> must hold the <i>query</i> for the database, and the result is returned in <b>msg.payload</b>.</p>
 | 
				
			||||||
 | 
					    <p><b>msg.payload</b> can contain an array of values to bind to the topic.</p>
 | 
				
			||||||
    <p>Typically the returned payload will be an array of the result rows, (or an error).</p>
 | 
					    <p>Typically the returned payload will be an array of the result rows, (or an error).</p>
 | 
				
			||||||
    <p>The reconnect timeout in milliseconds can be changed by adding a line to <b>settings.js</b>
 | 
					    <p>The reconnect timeout in milliseconds can be changed by adding a line to <b>settings.js</b>
 | 
				
			||||||
    <pre>sqliteReconnectTime: 20000,</pre></p>
 | 
					    <pre>sqliteReconnectTime: 20000,</pre></p>
 | 
				
			||||||
 
 | 
				
			|||||||
@@ -57,7 +57,8 @@ module.exports = function(RED) {
 | 
				
			|||||||
            node.on("input", function(msg) {
 | 
					            node.on("input", function(msg) {
 | 
				
			||||||
                if (typeof msg.topic === 'string') {
 | 
					                if (typeof msg.topic === 'string') {
 | 
				
			||||||
                    //console.log("query:",msg.topic);
 | 
					                    //console.log("query:",msg.topic);
 | 
				
			||||||
                    node.mydbConfig.db.all(msg.topic, function(err, row) {
 | 
					                    var bind = Array.isArray(msg.payload) ? msg.payload : [];
 | 
				
			||||||
 | 
					                    node.mydbConfig.db.all(msg.topic, bind, function(err, row) {
 | 
				
			||||||
                        if (err) { node.warn(err); }
 | 
					                        if (err) { node.warn(err); }
 | 
				
			||||||
                        else {
 | 
					                        else {
 | 
				
			||||||
                            msg.payload = row;
 | 
					                            msg.payload = row;
 | 
				
			||||||
 
 | 
				
			|||||||
		Reference in New Issue
	
	Block a user