-
Notifications
You must be signed in to change notification settings - Fork 80
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Query function is actually called 3 times in express #57
Comments
What is the query like? What database engine? In my experience, a query like the following will generate two result sets with SQL Server:
The first result set has no row data but it does return a "rows affected" count. The same thing occurs if you insert into a temporary table or update/delete rows from a table. And it is solved by prefixing the query with |
I'm calling a stored procedure on a Sybase Anywhere DB. the db.query should only be called once and in express when I call the route I've got 2 different result (see the code above). Also it doesn't wait for the promise to be resolved (apparently). The first time result is [] and the second time it got the rows. So in Express it called the res.send with the empty array and doesn't send the one with the rows in it. |
Here is a full example (still using Sybase Anywhere 9 DB). Query (queries.LIST)
Code
Result
It's called 3 times! I only call the route '/list' once. It actually only res.send the first empty row and then :
|
Check the value of You could then change your code to something like: router.get("/list/", (req, res, next) => {
try {
...
const parameters = [userId];
db.query(queries.LIST, parameters, (err, rows, moreResultSets) => {
if (err) {
return res.status(400).json({ error: `an error occured: ${err}` });
}
console.log(rows);
if (!moreResultSets) {
return res.status(200).send(rows);
}
});
} catch (e) {
next(e);
}
}); |
Thanks, I'll try that. Maybe the issue come from the stored procedure that's being called on the DB side (Sybase Anywhere 9). I know I've received warnings (The result returned is non deterministic SQLCode=122) on InteractiveSQL. Edit: Your code works with the query, thanks 👍 |
Hi there, Is it possible to access somehow "moreResultsSets" with querySync ? Thanks 👍 |
I think I have the same error. I am using nodejs & express on sql server. |
Hi there,
I've a weird issue there :
The db.query function is somehow called 2 times and I don't know why exactly.
The first time it return an empty array, the second time the good one.
I'm using Express and it causes a lot of issues with res.send.
Thanks for the help 👍
The text was updated successfully, but these errors were encountered: