Add bind capability to sqlite and mysql nodes

Thanks to Scott Penrose for the patch.
This commit is contained in:
dceejay
2015-01-26 10:57:13 +00:00
parent d7dc9dae20
commit 5982da8495
6 changed files with 10 additions and 6 deletions

View File

@@ -79,6 +79,7 @@
<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>
<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>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>

View File

@@ -101,7 +101,8 @@ module.exports = function(RED) {
node.on("input", function(msg) {
if (typeof msg.topic === 'string') {
//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); }
else {
msg.payload = rows;

View File

@@ -1,9 +1,9 @@
{
"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",
"dependencies" : {
"mysql" : "2.3.*"
"mysql" : "2.5.*"
},
"repository" : {
"type":"git",