Repository navigation
TVP TYPE.date not working #889
Copy link
Copy link
Closed
Labels
Action RequiredAn action is needed by Tedious memberFix in current PRA PR waiting to be merged for this issue's fix
Description
Hi, i'm trying to send a TVP with one column type.date value.
Code example
this is my function
function set(req, res) {
var params = req.body;
var table = {
columns: [
{name: 'id_service', type: TYPES.Int },
{name: 'id_office', type: TYPES.NVarChar },
{name: 'disabled_days', type: TYPES.NVarChar },
{name: 'creation_date', type: TYPES.Date},
{name: 'creation_user', type: TYPES.NVarChar}
],
rows: [
]
};
for ( var i = 0; i < params.office.length; i++ ) {
var office = [
Number (params.office[i].idService ),
params.office[i].idOffice,
params.office[i].disabledDays,
datesService.getTodayToSql(), //today's date in format yyyy/mm/dd '2019/04/10'
'user'
];
table.rows.push (office);
}
var param = {
fecha : {
type: TYPES.Date, value:datesService.getTodayToSql() //today's date in format yyyy/mm/dd '2019/04/10'
}
}
conn.executeSPTVP ( "set_office_closed", table, param )
.then (response =>{
res.status(200).json({ doc:response });
})
.catch (error => {
res.status(400).json({ message: 'error', result:error });
});
}
exports.executeSPTVP = function(storedProcedure, table, params) {
return new Promise((resolve, reject) => {
var jsonArray = [];
connService.acquire(function(err, connection) {
if (err) {
console.error(err);
return;
}
let request = new Request(storedProcedure, function(err, rowCount ) {
if (err) {
reject(err);
} else {
resolve(jsonArray);
}
connection.release();
});
request.on('row', function(columns) {
var obj = {};
for (var property in columns) {
obj[property] = columns[property].value;
}
jsonArray.push(obj);
});
request.addParameter('tvp', TYPES.TVP, table); //add the table as parameter
if (params) {
for (var param in params) {
request.addParameter(param, params[param].type, params[param].value); //add fecha as parameter
}
}
connection.callProcedure(request);
});
});
}when I print creation_date in sql store procedure, it returns 0001-01-01T00:00:00.000Z //bad
when I print fecha in sql store procedure, it returns 2019-04-10T00:00:00.000Z //ok
these are my dependencies
"dependencies": {
"async": "^2.6.2",
"body-parser": "^1.18.3",
"express": "^4.16.4",
"moment": "^2.24.0",
"tedious": "^6.1.0",
"tedious-connection-pool": "^1.0.5"
}Metadata
Metadata
Assignees
Labels
Action RequiredAn action is needed by Tedious memberFix in current PRA PR waiting to be merged for this issue's fix
Activity
MichaelSun90 commentedon Apr 12, 2019
Hi @marianolop22
Just created a local simple repo script, and confirmed this actually is an issue from Tedious side. Currently for Date type, Tedious does not fully handle the format 'YYYY/MM/DD', which cause the wrong value. We will figure out a fix for this as soon as possible.
arthurschreiber commentedon Jan 3, 2020
I think this was fixed via #1023.