1
0
mirror of https://github.com/node-red/node-red-nodes.git synced 2023-10-10 13:36:58 +02:00

fix mysql node OkPacket handling

to close #583
This commit is contained in:
Dave Conway-Jones 2019-10-16 11:24:33 +01:00
parent b35daf6bb7
commit f2e28e715f
No known key found for this signature in database
GPG Key ID: 302A6725C594817F
2 changed files with 18 additions and 13 deletions

View File

@ -121,7 +121,6 @@ module.exports = function(RED) {
node.on("input", function(msg) { node.on("input", function(msg) {
if (node.mydbConfig.connected) { if (node.mydbConfig.connected) {
if (typeof msg.topic === 'string') { if (typeof msg.topic === 'string') {
//console.log("query:",msg.topic);
var bind = Array.isArray(msg.payload) ? msg.payload : []; var bind = Array.isArray(msg.payload) ? msg.payload : [];
node.mydbConfig.connection.query(msg.topic, bind, function(err, rows) { node.mydbConfig.connection.query(msg.topic, bind, function(err, rows) {
if (err) { if (err) {
@ -129,7 +128,10 @@ module.exports = function(RED) {
status = {fill:"red",shape:"ring",text:"Error"}; status = {fill:"red",shape:"ring",text:"Error"};
} }
else { else {
msg.payload = rows; if (rows.constructor.name === "OkPacket") {
msg.payload = JSON.parse(JSON.stringify(rows));
}
else { msg.payload = rows; }
node.send(msg); node.send(msg);
status = {fill:"green",shape:"dot",text:"OK"}; status = {fill:"green",shape:"dot",text:"OK"};
} }

View File

@ -1,18 +1,21 @@
{ {
"name" : "node-red-node-mysql", "name": "node-red-node-mysql",
"version" : "0.0.18", "version": "0.0.19",
"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.16.0" "mysql": "^2.17.1"
}, },
"repository" : { "repository": {
"type":"git", "type": "git",
"url":"https://github.com/node-red/node-red-nodes/tree/master/storage/mysql" "url": "https://github.com/node-red/node-red-nodes/tree/master/storage/mysql"
}, },
"license": "Apache-2.0", "license": "Apache-2.0",
"keywords": [ "node-red", "mysql" ], "keywords": [
"node-red" : { "node-red",
"nodes" : { "mysql"
],
"node-red": {
"nodes": {
"mysql": "68-mysql.js" "mysql": "68-mysql.js"
} }
}, },