N
N
Nicholas2015-09-03 15:07:22
MySQL
Nicholas, 2015-09-03 15:07:22

Mysql how to know query conditions when responding?

I make a request:

'SELECT * FROM `Method_Arguments` WHERE `id` = "1"'

How can I find out the request itself when receiving a response?)) I'm
interested in the id
It is possible to do so result[0].id but what to do if there are no matches in the database?
mysql_connection.query('SELECT * FROM `Method_Arguments` WHERE `id` = "1010" ', function(err, result) {	
  if (err){
    err=null;result=null; console.log(" Get err");  return;
  };
  
  if(result.length > 0)
  {
  
  }else{
    console.log(' тут выводим ид из  WHERE `id` = "1010"  ' );
  }
})

Answer the question

In order to leave comments, you need to log in

3 answer(s)
N
Nicholas, 2015-09-03
@ACCNCC

Solved the problem through "Multiple statement queries"

M
Max, 2015-09-03
@MaxDukov

if there are no matches - get an empty answer.
redirect the response to a variable, parse it - and return the response depending on the content.
And, by the way, what is the meaning of the task?

A
Alexander Prozorov, 2015-09-05
@Staltec

And why through the closure is not satisfied?

// Экспрессовский app.get() приведён для демонстрации контекста потока
app.get('/users/:id', function (req, res, next) {
  var id = req.params.id|0; // /users/1010 -> id = 1010;

  mysql_connection.query("SELECT * FROM `Method_Arguments` WHERE `id`=?", [id], 
    function (err, result) {	
      if (err) return next(err);
  
      if (result.length > 0)  {
        console.log(result);
      } else {
        console.log(id); // тут выводим id из  WHERE
      }
  });
});

UPD : corrected the code so that the context of the id closure was clear.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question