Mysql Query in Node ignoring difference condition

Asked

Viewed 116 times

1

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 lines with category 2, and despite rewriting the code several times and trying other ways to get the result, including treatment on the client side (by selecting the category and making a if(objeto.categoria !=2)). Doesn’t work.

This is about a bug? Or it could be something in my code that I’m missing?

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)
    }
});
  • have tried to do as our colleague put in the answer to that question link, instead of the fixed value would pass ? , then pass the values in an array as the second parameter in the query method

  • I tried and yet SELECT is returning lines with category = 2

  • Try changing your parole <> for !=

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.