0

I want to call a stored procedure and get the return value in node. I'm able to do it 2 calls. 1 for calling procedure and the other for returning value.

I'm using mysql module

sqlcon.query("call CountOrderByStatus('done',@total);", function(err, rows, fields) {
                if (!err) {
                    console.log(rows);
                }
                else{
                    console.log('Error while performing Query.');
                    console.error(err)
                }
            });
            sqlcon.query("select @total;", function(err, rows, fields) {
                if (!err) {
                    console.log(rows);

                }
                else{
                    console.log('Error while performing Query.');
                    console.error(err)
                }
            });
        });

Is there any way to get it it one call?.

1 Answer 1

1

You can do something like this in node-mysql

sqlcon.query('SELECT 1; SELECT 2', function(err, results) {
  if (err) throw err;

  // `results` is an array with one element for every statement in the query:
  console.log(results[0]); // [{1: 1}]
  console.log(results[1]); // [{2: 2}]
});

Sign up to request clarification or add additional context in comments.

2 Comments

That is throwing error.. Whenever we use 2 queries in single query
You need to use {multipleStatements: true} while creating connection. Something like this: var sqlcon = mysql.createConnection({multipleStatements: true});

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.