Send data to Mariadb using NodeRed ("Error: ER_EMPTY_QUERY: Query was empty")

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

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

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

Good day Colin,

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

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

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.

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