Reputation: 2741
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?.
Upvotes: 0
Views: 6136
Reputation: 2461
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}]
});
Upvotes: 1