I have had a peculiar problem while changing my Node.JS server to certain MySQL queries. I have the following code that works normally in MySQL Workbench:
SELECT id, nome FROM 'tabela' WHERE categoria <> 2;
But in node-mysql the query continues to select rows with a category of 2, and despite rewriting the code several times and trying other ways to get the result, including client-side handling (by selecting the category and doing a if(objeto.categoria !=2)
). It does not work.
Is this a bug ? Or could it be something in my code that I'm not aware of?
The code snippets where I make the selection, in more detail, are available below:
// Evento para requisição WebSocket - Lado Server
socket.on('req-table-list', function(){
db.query("SELECT id, nome FROM 'banco_de_dados'.'tabela' WHERE categoria <> 2", function(err, rows){
if(err){
socket.emit('res-table-list', {content: null, error: err.code});
}
else{
socket.emit('res-table-list', {content: rows, error: null});
}
});
});
// Evento para resposta WebSocket - Lado Client
socket.on('res-table-list', function(data){
for(var i=0; i<data.content.length; i++){
$("#myDiv").append(data.content[i].nome + '-' + data.content[i].id)
}
});