Skip to content
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

request.output + OUTPUT clause returns value in recordset field instead of output field #1562

Open
RicardoAALL opened this issue Oct 11, 2023 · 1 comment

Comments

@RicardoAALL
Copy link

RicardoAALL commented Oct 11, 2023

Perhaps, I'm misunderstanding how the output method works but here is the code I am using:

Executing the following code

const fullName = "bob smith"
let inserted = await sql.connect(sqlConfig).request()
  .input('FullName', sql.NVarChar(255), fullName)
  .output('ID', sql.Int)
  .query(`
    INSERT INTO test.dbo.test_table(FullName) 
    OUTPUT INSERTED.ID 
    VALUES(@FullName)
  `)
console.log(inserted)

Expected behaviour:

I expected the value returned to be accessed using:

inserted.output

Actual behaviour:

In order to actually access the output value I have to use the recordset field:

inserted.recordset[0].ID

The output field does show the ID property but the value is set to null.

Configuration:

// basic config from example

Software versions

  • NodeJS: 18+
  • node-mssql: 10.0.1
  • SQL Server: 2019
@dhensby
Copy link
Collaborator

dhensby commented Nov 7, 2023

Sorry for the delay in looking into this.

I also see that behaviour and it is indeed a bit confusing. I think the recordset(s) is the right place for this data to be populated and the presence of the output property is confusing. If you insert many rows, this should be an array of data, not a fixed object, so the implied access of inserted.output.ID would be incorrect.

I'll do some digging into the output property and what we can / should do with it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants