Pergunta

QUESTION: I am writing a node.js code on server which accepts multiple values from client on certain event

var table = data['table'];
var columnName  = data['colName']
var columnValue = data['colValue']
var primary_id = data['pid']

var updateQuery = "UPDATE "+table+" SET "+columnName+"=? WHERE primary_id="+primary_id;

var query = conn.query(updateQuery, [columnValue] , function (err, result) {
              if (err) throw err;

              console.log('changed ' + result.changedRows + ' rows');
            });

console.log(query.sql);
// This shows exact query which I wanted to RUN against my MySQL db and also executes successfully on my DB if I try to run this manually.

Problem:

  1. Query formed is correct still that query is not executing through NODE server.
  2. NODE not showing any error thrown on anonymous call back function and not even result.

    NOTE : I have tried to RUN simple select through NODE and that works perfectly [all inclusion are are made correctly for mysql module and its connection object]

It would be great if some body put some lights on further how to debug this in terms of what kind of error its getting in back-end.

Foi útil?

Solução

Its was silly mistake ... I was destroying connection each time.

So due to asynchronous nature of JS which indeed used in NODE execution was flowing down with out stopping for query to execute. ..Yes offcourse there is possibly option in NODE to use synchronous nature.

but for now when I removed that line it works like a charm. //conn.destroy();

Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top