Duplicate input and/or output query params results in undefined behavior
See original GitHub issueSpinning this off from #634.
If request.input()
param names match request.output()
param names in the same request.query()
, there is no error thrown, but the result may not be what the user expected.
This bit me when I was trying to do a SELECT
and had used the same @name
param as a column return value and a bind-argument:
const name = 'test-user';
const result = await pool
.request()
.input('name', sql.VarChar(255), name)
.output('id', sql.BigInt)
.output('name', sql.VarChar(255))
.output('created_on', sql.DateTime2(3))
.query(`SELECT TOP 1 [id], [name], [created_on] FROM users WHERE name = @name`);
if (result.recordsets.length !== 1 || result.recordsets[0].length !== 1) {
// no results
return;
}
const row = result.recordsets[0][0];
console.log(`#${row.id}, ${row.name}`);
To fix the issue, I changed input('name', ...)
to input('name_query', ...)
and @name
to @name_query
. It may be nice to throw some error here if that happens? Maybe log a warning?
Issue Analytics
- State:
- Created 5 years ago
- Reactions:2
- Comments:5
Top Results From Across the Web
Undefined values causing problems with inputs #52 - GitHub
I have a component Filter which the user interacts with through input controls in order to specify a filter, which should then be...
Read more >Undefined when returning 'results' parameter from mysql query
So why data is equal to 'undefined' if i'm returning the 'results' array? and how can i solve this? I'm new in Node.js,...
Read more >Under-Constrained Symbolic Execution with Crucible
Sure, perhaps your library function my_div has undefined behavior when it's second argument is zero, but that's probably expected, it might even ...
Read more >Sure, multiple query params with the same name are...
So the outcome is consistent: multiple params with the same name become an Array, which is then stringified using the default JS behavior...
Read more >CGI - Simple Common Gateway Interface Class
print $query->textfield('field_name','starting value',50,80);. textfield() will return a text input field. Parameters: The first parameter is the required name ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
ah, ok. that’s a bit annoying!
I would make clear, however, it’s best to properly type your bulk data rather than relying on the library to do it