Comments (8)
var TYPES = require('tedious').TYPES;
var request = new Request('my_proc', function(err) {
....
});
var string = 'some text';
var number = 7;
request.addParameter(TYPES.VarChar, 'parameterName', string);
request.addParameter(TYPES.Int, 'anotherParameterName', number);
request.addOutputParameter(TYPES.VarChar, 'outputParameterName', {length: 10}); // varchar(10)
request.on('returnValue', function(parameterName, value, metadata) {
console.log(parameterName + ' = ' + value); // outputParameterName = ...
});
connection.callProcedure(request);
Note: I am not convinced that the API is quite right. There's a good chance that it will change.
from tedious.
Please note, the first two arguments to the Request.addParameter
and Request.addOutputParameter
functions have been swapped around. The first argument is now the parameter name.
request.addParameter('parameterName', TYPES.VarChar, string);
request.addParameter('anotherParameterName', TYPES.Int, number);
from tedious.
It should be possible to call stored procedures now, but in a quite limited way. If you don't need any output parameters, then you can use a Request
to execute a statement that just happens to be a stored procedure.
For example, sp_who
accepts no parameters, and outputs a result set. So it can be treated the same as the execution of any select statement.
Input parameters can passed using string concatention.
var sql = "exec my_proc @myParam = '" + value + "'";
new Request(sql, ...)
Of course this is horrible, and not a good strategy. Issue #14 will introduce support for execution of parameterised requests, which will remove the need for that approach. I intend to work on it soon, and expect it to be in the next release. It will only support a small number of data types for parameters intially.
Once parameterised requests are in place, it shouldn't require too much work to provide a decent API for execution of stored procedures.
from tedious.
I don't mind running "exec my_proc" strings as SQL statements; it seems to work except the row count comes back undefined in these cases.
from tedious.
Support for executing stored procedures, including passing input and output parameters has been added.
So far only tinyint
, smallint
, int
, varchar
and nvarchar
are supported.
The documentation has not been updated yet.
from tedious.
Could you post a sample code to call a stored procedure using input/output parameters?
Thanks.
from tedious.
Thanks!
from tedious.
Included in v0.0.4.
from tedious.
Related Issues (20)
- Need to update @azure/msal-node to 2.0 for NodeJs 20 compatability HOT 9
- Login failure with caret (^) in password HOT 2
- [FEATURE REQUEST] HOT 3
- README Getting Started Links Out-of-Date HOT 1
- [FEATURE REQUEST] Connection socket ref/unref HOT 1
- Getting RangeError [ERR_OUT_OF_RANGE] for "smalldatetime" type column while using bulk insert HOT 10
- https://salla.sa//bero-2030.com HOT 1
- Pre 2001 Dates throws Out of Range Error when using params HOT 3
- MSSQL Connection problem HOT 3
- support with tauri application HOT 1
- link in readme is broken HOT 2
- Getting RangeError and Nodejs throws error for "bigint" type column if float values are provided in bulk load while using bulk insert HOT 4
- Cannot find name 'AggregateError'. HOT 5
- SmallDateTime has incorrect upper bound range (fix PR included) HOT 1
- [FEATURE REQUEST] Custom `ChainedTokenCredential` HOT 2
- [FEATURE REQUEST] Modernize ESLint HOT 5
- [QUESTION] `azure-active-directory-default` Auto Token Refresh? HOT 6
- [FEATURE REQUEST] Supply Chain Security Analisys HOT 1
- [FEATURE REQUEST] Better IDE Integration HOT 5
- [FEATURE REQUEST] Unify Programming Languages to a Single Standard HOT 1
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 tedious.