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,6 +78,7 @@ 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"});
@ -82,6 +86,7 @@ module.exports = function(RED) {
} }
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,6 +96,7 @@ 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);
@ -100,6 +106,7 @@ module.exports = function(RED) {
} }
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,6 +115,7 @@ module.exports = function(RED) {
} }
}); });
} }
}
else { else {
if (node.sql === null || node.sql == "") { if (node.sql === null || node.sql == "") {
node.error("Prepared statement config not set up",msg); node.error("Prepared statement config not set up",msg);