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

mysql - ensure connection released back to pool more often

and try to ensure status is shown more correctly on error.
This commit is contained in:
Dave Conway-Jones 2020-04-05 11:44:27 +01:00
parent ea3ed9ff5e
commit 705dd1ffc1
No known key found for this signature in database
GPG Key ID: 302A6725C594817F
2 changed files with 6 additions and 3 deletions

View File

@ -19,8 +19,8 @@ module.exports = function(RED) {
function checkVer() {
node.connection.query("SELECT version();", [], function(err, rows) {
node.connection.release();
if (err) {
node.connection.release();
node.error(err);
node.status({fill:"red",shape:"ring",text:"Bad Ping"});
doConnect();
@ -86,6 +86,7 @@ module.exports = function(RED) {
if (this.tick) { clearTimeout(this.tick); }
if (this.check) { clearInterval(this.check); }
node.connected = false;
node.connection.release();
node.emit("state"," ");
node.pool.end(function (err) { done(); });
});
@ -124,8 +125,9 @@ module.exports = function(RED) {
var bind = Array.isArray(msg.payload) ? msg.payload : [];
node.mydbConfig.connection.query(msg.topic, bind, function(err, rows) {
if (err) {
status = {fill:"red",shape:"ring",text:"Error: "+err.code};
node.status(status);
node.error(err,msg);
status = {fill:"red",shape:"ring",text:"Error"};
}
else {
if (rows.constructor.name === "OkPacket") {
@ -134,6 +136,7 @@ module.exports = function(RED) {
else { msg.payload = rows; }
node.send(msg);
status = {fill:"green",shape:"dot",text:"OK"};
node.status(status);
}
});
}

View File

@ -1,6 +1,6 @@
{
"name": "node-red-node-mysql",
"version": "0.0.20",
"version": "0.0.21",
"description": "A Node-RED node to read and write to a MySQL database",
"dependencies": {
"mysql": "^2.18.1"