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

sqlite - better handle extensions timing

This commit is contained in:
Dave Conway-Jones 2018-08-22 23:47:03 +01:00
parent 665a8666ab
commit 0b65cd8652
No known key found for this signature in database
GPG Key ID: 9E7F9C73F5168CD4
2 changed files with 46 additions and 38 deletions

View File

@ -1,6 +1,6 @@
{ {
"name": "node-red-node-sqlite", "name": "node-red-node-sqlite",
"version": "0.3.3", "version": "0.3.4",
"description": "A sqlite node for Node-RED", "description": "A sqlite node for Node-RED",
"dependencies": { "dependencies": {
"sqlite3": "^4.0.2" "sqlite3": "^4.0.2"

View File

@ -51,6 +51,7 @@ module.exports = function(RED) {
var doQuery = function(msg) { var doQuery = function(msg) {
if (node.sqlquery == "msg.topic"){ if (node.sqlquery == "msg.topic"){
if (typeof msg.topic === 'string') { if (typeof msg.topic === 'string') {
if (msg.topic.length > 0) {
bind = Array.isArray(msg.payload) ? msg.payload : []; bind = Array.isArray(msg.payload) ? msg.payload : [];
node.mydbConfig.db.all(msg.topic, bind, function(err, row) { node.mydbConfig.db.all(msg.topic, bind, function(err, row) {
if (err) { node.error(err,msg); } if (err) { node.error(err,msg); }
@ -60,6 +61,7 @@ module.exports = function(RED) {
} }
}); });
} }
}
else { else {
node.error("msg.topic : the query is not defined as a string",msg); node.error("msg.topic : the query is not defined as a string",msg);
node.status({fill:"red",shape:"dot",text:"msg.topic error"}); node.status({fill:"red",shape:"dot",text:"msg.topic error"});
@ -67,6 +69,7 @@ module.exports = function(RED) {
} }
if (node.sqlquery == "batch") { if (node.sqlquery == "batch") {
if (typeof msg.topic === 'string') { if (typeof msg.topic === 'string') {
if (msg.topic.length > 0) {
node.mydbConfig.db.exec(msg.topic, function(err) { node.mydbConfig.db.exec(msg.topic, function(err) {
if (err) { node.error(err,msg);} if (err) { node.error(err,msg);}
else { else {
@ -75,13 +78,15 @@ module.exports = function(RED) {
} }
}); });
} }
}
else { else {
node.error("msg.topic : the query is not defined as string", msg); node.error("msg.topic : the query is not defined as string", msg);
node.status({fill:"red", shape:"dot",text:"msg.topic error"}); node.status({fill:"red", shape:"dot",text:"msg.topic error"});
} }
} }
if (node.sqlquery == "fixed"){ if (node.sqlquery == "fixed"){
if (typeof node.sql === 'string'){ if (typeof node.sql === 'string') {
if (msg.payload && msg.payload.length > 0) {
bind = Array.isArray(msg.payload) ? msg.payload : []; bind = Array.isArray(msg.payload) ? msg.payload : [];
node.mydbConfig.db.all(node.sql, bind, function(err, row) { node.mydbConfig.db.all(node.sql, bind, function(err, row) {
if (err) { node.error(err,msg); } if (err) { node.error(err,msg); }
@ -91,15 +96,17 @@ module.exports = function(RED) {
} }
}); });
} }
}
else{ else{
if (node.sql === null || node.sql == ""){ if (node.sql === null || node.sql == "") {
node.error("SQL statement config not set up",msg); node.error("SQL statement config not set up",msg);
node.status({fill:"red",shape:"dot",text:"SQL config not set up"}); node.status({fill:"red",shape:"dot",text:"SQL config not set up"});
} }
} }
} }
if (node.sqlquery == "prepared"){ if (node.sqlquery == "prepared"){
if (typeof node.sql === 'string' && typeof msg.params !== "undefined" && typeof msg.params === "object"){ if (typeof node.sql === 'string' && typeof msg.params !== "undefined" && typeof msg.params === "object") {
if (node.sql.length > 0) {
node.mydbConfig.db.all(node.sql, msg.params, function(err, row) { node.mydbConfig.db.all(node.sql, msg.params, function(err, row) {
if (err) { node.error(err,msg); } if (err) { node.error(err,msg); }
else { else {
@ -108,16 +115,17 @@ module.exports = function(RED) {
} }
}); });
} }
else{ }
if (node.sql === null || node.sql == ""){ else {
if (node.sql === null || node.sql == "") {
node.error("Prepared statement config not set up",msg); node.error("Prepared statement config not set up",msg);
node.status({fill:"red",shape:"dot",text:"Prepared statement not set up"}); node.status({fill:"red",shape:"dot",text:"Prepared statement not set up"});
} }
if (typeof msg.params == "undefined"){ if (typeof msg.params == "undefined") {
node.error("msg.params not passed"); node.error("msg.params not passed");
node.status({fill:"red",shape:"dot",text:"msg.params not defined"}); node.status({fill:"red",shape:"dot",text:"msg.params not defined"});
} }
else if (typeof msg.params != "object"){ else if (typeof msg.params != "object") {
node.error("msg.params not an object"); node.error("msg.params not an object");
node.status({fill:"red",shape:"dot",text:"msg.params not an object"}); node.status({fill:"red",shape:"dot",text:"msg.params not an object"});
} }