jeudi 2 avril 2015

How dynamically assigning values ​​to a property of an object?

I am coding a node module with mssql for node.js, in this module I have a function called sp_recordset which allows to execute a stored procedure by just sending a db conexion, the name of the stored procedure, the parameters, I added a callback function to return my recordset, in the parameters I send an array with the names of the parameters, the values and the SqlServer data types , this is the Array:



[{name:'num',type:'Int',value:2},
{name:'num1',type:'Int',value:1}]


This is my function:



exports.sp_recordset = function(conex,storeProcedure,parameters,cb){

var connection = new mssql.Connection(conex, function(err) {
if(err){
console.log(err);
}

var request = new mssql.Request(connection);

for(index=0;index<parameters.length;++index)
{
request.input(parameters.name, mssql.Int, parameters.value);
}

request.execute(storeProcedure, function(err, recordsets, returnValue) {
if(err){
console.log(err);
}
cb(recordsets);
});

});

};


In this line line is my problem:



request.input(parameters.name, mssql.Int, parameters.value);


As I said, the need is a dynamic function, the second parameter (SqlServer Data type also has to by dynamic), which is the best way to assign the data type to mssql? I have tried this but it doesn't works:



request.input(parameters.name, mssql.(parameters.type), parameters.value);

Aucun commentaire:

Enregistrer un commentaire