tedious icon indicating copy to clipboard operation
tedious copied to clipboard

Support for Table-Valued Parameters in execSql

Open mastodon0 opened this issue 4 years ago • 1 comments

Calling execSql with a TVP results in the error

Could not find stored procedure 'sp_executesql'

Example code:

var table = {
    schema: 'dbo',
    name: 'MyTVP',
    columns: [
        { name: 'Name', type: TYPES.VarChar, length: 50 },
        { name: 'Rating', type: TYPES.Int },
    ],
    rows: [['Foo', 1]]
};

var request = new Request('select * from @TVP', (err) => {
        if (err) {
            console.log(err);
        }

        connection.close();
    }
);

request.addParameter('TVP', TYPES.TVP, table);

connection.execSql(request);

mastodon0 avatar Nov 26 '20 22:11 mastodon0

Thanks for raising this issue, I'll take a closer look at it soon!

IanChokS avatar Nov 30 '20 19:11 IanChokS

How is this going? Every time I want to use TVP I have to implement procedures where I really want to use ordinary SQL statements (TSQL).

For my part it fails with The procedure "sp_executesql" has no parameter named "@<tvp input name>". when using tedious through mssql@^9

lostfields avatar Jun 05 '23 11:06 lostfields

Hi @lostfields , this PR #1327 seems has the changes for this issue. Can you give it a try, see if it fixes your issue? If yes, we can work with @arthurschreiber , see if we can merge and release this fix.

MichaelSun90 avatar Jun 05 '23 16:06 MichaelSun90

Wow, amazing @MichaelSun90 ! That branch worked out of the box through library mssql. I have only tested TVP, nothing more though.

lostfields avatar Jun 06 '23 10:06 lostfields

@lostfields , glad to know that works. We will try to get the fix out as soon as possible.

MichaelSun90 avatar Jun 07 '23 16:06 MichaelSun90

Fixed via https://github.com/tediousjs/tedious/pull/1327.

arthurschreiber avatar Jun 28 '23 19:06 arthurschreiber