Comments (12)
from node-sqlserver-v8.
from node-sqlserver-v8.
@TimelordUK : I guess when we use just import mssql it is using tedious TDS by default and when we use
await db
.request()
.input("tvpTable", tvp)
OR
await db
.request()
.input("tvpTable",sql.TYPES.TVP, tvp) it works fine.
But when we import sql/msnodesqlv8 this doesnt work and gives above mentioned error.
from node-sqlserver-v8.
I have been looking at adding TVP parameter stored proc support to msnodesqlv8
in my library all that will be required is a call to the proc with an object parameter where columns are defined.
i.e.
var tvpObj = {
col_1 : "Hello",
col_2 : "World"
}
and call the proc as usual - all the binding is done automatically by the driver.
I hope to have that released shortly but I will have to see how to integrate that into the mssql API.
from node-sqlserver-v8.
this is now fixed on latest version 0.4.5
from node-sqlserver-v8.
@TimelordUK , I cannot get this to work although I'm running version 0.4.7.
Try 1
const tvp = new sql.Table("[General].[BigintValueTVP]");
tvp.columns.add("value", sql.BigInt(), { nullable: false });
tvp.rows.add(1);
tvp.rows.add(2);
const request = new sql.Request(connection);
request.input("tTVP", tvp);
await request.execute("mySP");
Throws the same error as above: IMNOD: [msnodesql] Parameter 1: Invalid parameter type
Try 2
const tvp = [{value:1}, {value:2}]
const request = new sql.Request(this.connection);
request.input("tTVP", tvp);
await request.execute("mySP");
This throws the following error: Operand type clash: nvarchar is incompatible with BigintValueTVP
Try 3
const tvp = [{value:1}, {value:2}]
const request = new sql.Request(this.connection);
request.input("tTVP", sql.TVP("[General].[BigintValueTVP]"), tvp);
await request.execute("mySP");
This throws the first error: IMNOD: [msnodesql] Parameter 1: Invalid parameter type
So how do you work with TVPs when using this plugin?
from node-sqlserver-v8.
from node-sqlserver-v8.
Thanks for your reply @TimelordUK , but even after the patch this does not work. If the TVP is in the dbo schema all works, but if it is in a custom scheme (like in my examples above) I get the following error:
Column, parameter, or variable #1: Cannot find data type BigintValueTVP.
from node-sqlserver-v8.
Here is the test scenario I'm using:
DB Setup:
CREATE SCHEMA [Gen]
GO
CREATE TYPE [dbo].[Test1] AS TABLE(
[value] [bigint] NOT NULL
)
GO
CREATE TYPE [Gen].[Test] AS TABLE(
[value] [bigint] NOT NULL
)
GO
CREATE PROCEDURE [Gen].[TestSp]
@t [Gen].[Test] READONLY
AS
BEGIN
select *
from @t
END
GO
CREATE PROCEDURE [Gen].[TestSp1]
@t [Test1] READONLY
AS
BEGIN
select *
from @t
END
GO
app
var sql = require("mssql/msnodesqlv8");
var connection = new sql.ConnectionPool(config);
connection.connect()
.then(function () {
// This one is ok
var tvp = new sql.Table("Test1");
tvp.columns.add("value", sql.BigInt(), { nullable: false });
tvp.rows.add(5);
const request = new sql.Request(connection);
request.input("t", sql.TVP("Test1"), tvp);
request.execute("Gen.TestSp1")
.then(function () {
console.log("OK");
})
.catch(function (e) {
console.log(e);
});
// This one fails
var tvp = new sql.Table("Gen.Test");
tvp.columns.add("value", sql.BigInt(), { nullable: false });
tvp.rows.add(5);
const request = new sql.Request(connection);
request.input("t", sql.TVP("Gen.Test"), tvp);
request.execute("Gen.TestSp")
.then(function () {
console.log("OK");
})
.catch(function (e) {
console.log(e);
});
})
.catch(function (e) { console.log(e) });
from node-sqlserver-v8.
OK, I have made some progress on this, unfortunately this will require a change to the c++ driver as it has to inform ODBC of the schema being used, I have hacked up an experimental build which gets your examples working.
I will hope to get this released in next day or 2 after tidying up and testing.
from node-sqlserver-v8.
0.4.9 should now run these 2 examples OK - thanks they are good tests.
C:\Program Files\nodejs\node.exe index.js
OK
OK
var sql = require('mssql/msnodesqlv8')
const connectionConf = {
user: '',
password: '',
database: 'scratch',
host: 'localhost',
connectionString: 'Driver={SQL Server Native Client 11.0}; Server=np:\\.\pipe\LOCALDB#EBF94DD0\tsql\query; Database={scratch}; Trusted_Connection=Yes;',
options: {
},
pool: {
max: 5,
min: 0,
idle: 10000
}
}
var connection = new sql.ConnectionPool(connectionConf)
connection.connect()
.then(function () {
// This one is ok
var tvp = new sql.Table('Test1')
tvp.columns.add('value', sql.BigInt(), {nullable: false})
tvp.rows.add(5)
const request = new sql.Request(connection)
request.input('t', sql.TVP('Test1'), tvp)
request.execute('Gen.TestSp1')
.then(function () {
console.log('OK')
})
.catch(function (e) {
console.log(e)
})
}).then(function () {
// This one fails
var tvp = new sql.Table('Gen.Test')
tvp.columns.add('value', sql.BigInt(), {nullable: false})
tvp.rows.add(5)
const request = new sql.Request(connection)
request.input('t', sql.TVP('Gen.Test'), tvp)
request.execute('Gen.TestSp')
.then(function () {
console.log('OK')
})
.catch(function (e) {
console.log(e)
})
})
from node-sqlserver-v8.
I believe this is now sorted - this has been merged to mssql so hopefully tvp now works OK
from node-sqlserver-v8.
Related Issues (20)
- Change node-gyp path to download nodejs headers from msnodesqlv8 installation HOT 2
- Why are database field names garbled when using Chinese fields? HOT 3
- msnodesqlv8 can't find sqltypes.h HOT 2
- install msnodesqlv8 through npm failed HOT 2
- Keep saying Module not found of sqlserverv8 HOT 6
- Question: Using prepared query with Pool
- unable to build on CentOS7 HOT 3
- Prebuilt binaries for Node 20 / alpine HOT 3
- Cannot use without 'require'? HOT 1
- Module not found: Can't resolve '../build/Release/sqlserverv8' HOT 10
- Module did not self-register: sqlserverv8.node HOT 7
- npm install --save msnodesqlv8 fails MSBuild.exe failed with exit code: 1 HOT 5
- import { SqlClient } from "msnodesqlv8/types"; Cannot find module 'msnodesqlv8/types' or its corresponding type declarations HOT 1
- Unable to initialize msnodesql during Hot Module Reload (HMR) HOT 2
- Security vulnerability detected in latest HOT 1
- uncaughtException: Cannot read properties of null (reading 'query') HOT 3
- `ConcreteColumnType.parseSS` method tampers with plain date strings HOT 3
- Cannot find module '../build/Release/sqlserverv8.node' - Windows 10 / node.js v20.11.0/v21.6.1 HOT 1
- npm install results in LNK1127: library is corrupt HOT 1
- Uncaught Exception: static Sybase = new ServerDialect("Sybase")
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from node-sqlserver-v8.