# Send data to Mariadb using NodeRed ("Error: ER\_EMPTY\_QUERY: Query was empty")

**URL:** <https://discourse.nodered.org/t/send-data-to-mariadb-using-nodered-error-er-empty-query-query-was-empty/4356>\
**Category:** General\
**Created:** [28 October 2018 13:50 UTC](https://discourse.nodered.org/t/send-data-to-mariadb-using-nodered-error-er-empty-query-query-was-empty/4356 "2018-10-28T13:50:57Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![tramanah](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/tramanah/32/9122_2.png) [@tramanah](https://discourse.nodered.org/u/tramanah)\
**Post date:** [28 October 2018 13:50 UTC](https://discourse.nodered.org/t/send-data-to-mariadb-using-nodered-error-er-empty-query-query-was-empty/4356/1 "2018-10-28T13:50:57Z")

</div>

Hi,

i am sending data to Mariadb and its works fine using Node RED. Its pop up error in idea situation where no data been send. While the code end in else conditions the error message pop up. May I know how to over this error. ("Error: ER\_EMPTY\_QUERY: Query was empty")

> Blockquotevar  
> status = context.get('status')||0;

var current = global.get("stdTime");  
var daycurrent = global.get("stdDayTime");

var m\_work\_start = global.get('Mor\_Shift\_Start');  
var m\_work\_end = global.get('Mor\_Shift\_Stop');

var n\_work\_start = global.get('Night\_Shift\_Start');  
var n\_work\_end = global.get('Night\_Shift\_Stop');

/\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\* Between Morning & Night Shift \*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*\*/  
//from night to morning  
if (current \> n\_work\_end && current \< m\_work\_start) {  
if(status === 0)  
msg.topic ="INSERT INTO overalldata (deviceID, prdline, line, pulse, sumPulse, time, outputPin, STtarget, shiftTRGT, STActual, different, targetACHV, cycleTime, remarks) VALUES ('1', 'line 1', '1', '0', '0', '"+daycurrent+"', 'RESET', '0', '0', '0', '0', '0', '1', 'ok')";  
status = 1;  
context.set('status',status);  
}

//from morning to night  
else if (current \< n\_work\_start && current \> m\_work\_end) {  
if(status === 0)  
msg.topic ="INSERT INTO overalldata (deviceID, prdline, line, pulse, sumPulse, time, outputPin, STtarget, shiftTRGT, STActual, different, targetACHV, cycleTime, remarks) VALUES ('1', 'line 1', '1', '0', '0', '"+daycurrent+"', 'RESET', '0', '0', '0', '0', '0', '1', 'ok')";  
status = 1;  
context.set('status',status);

}  
else{  
status = 0;  
context.set('status',status);  
}

msg.payload = status;  
return msg;

> Blockquote

 ![db](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/e/e4bf008e2ad685fe8d0c3f9a47a00f77135e657f.png)

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [28 October 2018 14:18 UTC](https://discourse.nodered.org/t/send-data-to-mariadb-using-nodered-error-er-empty-query-query-was-empty/4356/2 "2018-10-28T14:18:36Z")

</div>

If you want to stop your function node from sending a message then set msg to null  
Something like this

```auto
else{
status = 0;
context.set('status',status);
msg = null;
}
if (msg) msg.payload = status;
return msg;

```

---

<div class="post-metadata">

**Author:** ![tramanah](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/tramanah/32/9122_2.png) [@tramanah](https://discourse.nodered.org/u/tramanah)\
**Post date:** [29 October 2018 01:11 UTC](https://discourse.nodered.org/t/send-data-to-mariadb-using-nodered-error-er-empty-query-query-was-empty/4356/3 "2018-10-29T01:11:12Z")

</div>

Good day Colin,

I did try the method and the error still persist. I did attach the screen shoot.

 ![db1](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/2X/3/3f79def0c4c4588eea4c2c494f9d250f7a6977a2.png)

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [29 October 2018 07:34 UTC](https://discourse.nodered.org/t/send-data-to-mariadb-using-nodered-error-er-empty-query-query-was-empty/4356/4 "2018-10-29T07:34:46Z")

</div>

Put a debug on the output of the function node and see what message is giving the error.

---

<div class="post-metadata">

**Author:** ![Colin](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/colin/32/17040_2.png) [@Colin](https://discourse.nodered.org/u/Colin)\
**Post date:** [29 October 2018 07:39 UTC](https://discourse.nodered.org/t/send-data-to-mariadb-using-nodered-error-er-empty-query-query-was-empty/4356/5 "2018-10-29T07:39:32Z")

</div>

Just noticed that you only set the topic if status is zero. Otherwise it leaves the topic at whatever is in the message coming in. Perhaps you meant to save the previous topic in the context.

---

<div class="post-metadata">

**Author:** ![tramanah](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/tramanah/32/9122_2.png) [@tramanah](https://discourse.nodered.org/u/tramanah)\
**Post date:** [31 October 2018 01:44 UTC](https://discourse.nodered.org/t/send-data-to-mariadb-using-nodered-error-er-empty-query-query-was-empty/4356/6 "2018-10-31T01:44:41Z")

</div>

Yes, its true. Manage to resolve. Thank you for support. Do appreciate most.
