From f2e28e715f320b149e463980e89c187e13e7dc21 Mon Sep 17 00:00:00 2001 From: Dave Conway-Jones Date: Wed, 16 Oct 2019 11:24:33 +0100 Subject: [PATCH] fix mysql node OkPacket handling to close #583 --- storage/mysql/68-mysql.js | 6 ++++-- storage/mysql/package.json | 25 ++++++++++++++----------- 2 files changed, 18 insertions(+), 13 deletions(-) diff --git a/storage/mysql/68-mysql.js b/storage/mysql/68-mysql.js index 153c9389..4b4b8ac0 100644 --- a/storage/mysql/68-mysql.js +++ b/storage/mysql/68-mysql.js @@ -121,7 +121,6 @@ module.exports = function(RED) { node.on("input", function(msg) { if (node.mydbConfig.connected) { if (typeof msg.topic === 'string') { - //console.log("query:",msg.topic); var bind = Array.isArray(msg.payload) ? msg.payload : []; node.mydbConfig.connection.query(msg.topic, bind, function(err, rows) { if (err) { @@ -129,7 +128,10 @@ module.exports = function(RED) { status = {fill:"red",shape:"ring",text:"Error"}; } else { - msg.payload = rows; + if (rows.constructor.name === "OkPacket") { + msg.payload = JSON.parse(JSON.stringify(rows)); + } + else { msg.payload = rows; } node.send(msg); status = {fill:"green",shape:"dot",text:"OK"}; } diff --git a/storage/mysql/package.json b/storage/mysql/package.json index 5bb89701..b9621a33 100644 --- a/storage/mysql/package.json +++ b/storage/mysql/package.json @@ -1,18 +1,21 @@ { - "name" : "node-red-node-mysql", - "version" : "0.0.18", - "description" : "A Node-RED node to read and write to a MySQL database", - "dependencies" : { - "mysql" : "^2.16.0" + "name": "node-red-node-mysql", + "version": "0.0.19", + "description": "A Node-RED node to read and write to a MySQL database", + "dependencies": { + "mysql": "^2.17.1" }, - "repository" : { - "type":"git", - "url":"https://github.com/node-red/node-red-nodes/tree/master/storage/mysql" + "repository": { + "type": "git", + "url": "https://github.com/node-red/node-red-nodes/tree/master/storage/mysql" }, "license": "Apache-2.0", - "keywords": [ "node-red", "mysql" ], - "node-red" : { - "nodes" : { + "keywords": [ + "node-red", + "mysql" + ], + "node-red": { + "nodes": { "mysql": "68-mysql.js" } },