I have code, which should execute if the table is not in mysql or "NULL" or empty.
mysqlConnection.query('SELECT `something` FROM `here` WHERE `dog` = \'' +info+ '\'', function(err, row, fields) {
if(err) {
console.log('Error1');
return;
}
else if (!row.length) {
console.log('Error2');
return;
}
else if (row[0].something == 'NULL' || row[0].something == '') {
console.log('Error3');
return;
}
console.log('Works');
});
So the thing is, if "something" is not in mysql, console shows Error2, but if "something" is in mysql, but if its NULL, console shows Works, so whats the problem? Im checking if something is NULL, but it wont show Error3. If table is empty, it shows Error3. Thanks for help.
NULLthen it is not'NULL'(is a string containingNULL) or''(is an empty string), butnullorundefined(can't test it right now). So you need to test forrow[0].something === nullorrow[0].something === undefined\'' +info+ '\''because they might result in potential sql injections or at least not working queries if info contains'. Take a look at Escaping query values.console.log('Hello');that waymysqlConnection.query( ... console.log('Works'); }); console.log('Hello');? ThenHelloshould always appear beforeWorksor one of theErrormessages, otherwise it would (imho) a bug in themysqllib.