You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I'm trying to execute multiple requests using multiple connections. I don't really know if I'm doing it wrong.
After calling the function query 2 times in parallel, I always get the results of the last one called in both callbacks. No matter the parameters I set.
If I invert the functions calls, I keep getting the result of the last one called.. so SQL is correct.
The reason you're getting the same results in the first case is because you're running the same query. If you use a local variable for the SQL string, then that won't happen.
Here's what you're experiencing:
query called. Assigns query1 to config.query and opens connection1.
query called. Assigns query2 to config.query and opens connection2.
connection1 connects and runs a request with the value of config.query which is query2.
connection2 connects and runs a request with the value of config.query which is query2.
The reason it works when you create the request in the query function is because you capture the value of config.query before it is changed by the second call to query()
I'm using tedious with sql-server, and I have to return a json file.
The #1 problem I had was because my select was returning 3 rows because was a relation one-to-many tables.
For example:
id
id_model_car
1
3
1
2
2
1
2
2
2
4
3
4
The select was some like
SELECT * FROM table where id=1
Was returning 3 rows, but it's was justing showing in Postman the last row because was being replaced.
Activity
ivantodorovich commentedon Jan 28, 2015
Ok, after a few testing I managed to solve it. Here's how I fixed it, in case anyone needs it.
Don't create the new request inside the 'connect' event. Instead, do it next to the connection and then execute inside the 'connect' event.
It does feel like a bug, though.. I don't really know why it didn't work before. Am I doing something wrong with scopes?
Closing after this.
bretcope commentedon Jan 28, 2015
The reason you're getting the same results in the first case is because you're running the same query. If you use a local variable for the SQL string, then that won't happen.
Here's what you're experiencing:
querycalled. Assigns query1 toconfig.queryand opens connection1.querycalled. Assigns query2 toconfig.queryand opens connection2.config.querywhich is query2.config.querywhich is query2.The reason it works when you create the request in the
queryfunction is because you capture the value ofconfig.querybefore it is changed by the second call toquery()ivantodorovich commentedon Jan 28, 2015
Ohhh, I'm such an idiot!
It's amazingly clear now that you've explained it.
Thank you, @bretcope
naiieandrade commentedon Nov 19, 2018
Hey @ivantodorovich or anyelse, if you could help me.
I'm using tedious with sql-server, and I have to return a
jsonfile.The #1 problem I had was because my select was returning 3 rows because was a relation one-to-many tables.
For example:
The select was some like
Was returning 3 rows, but it's was justing showing in Postman the last row because was being replaced.
And I need this return:
To do this, I think I need two selects. One to get id, name, isSenior, commissionPct and another to put in a list for jobHistory.
Do you can help me?
saketnimbargi commentedon Mar 2, 2020
@naiieandrade could you share your code snippet for better understanding.