Skip to content

TVP TYPE.date not working #889

Closed
Closed

Description

@marianolop22

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"
  }

Activity

  1. MichaelSun90 commented on Apr 12, 2019

    @MichaelSun90
    Contributor

    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.

  2. added
    Fix in current PR
    Follow up
    Action Required
    and removed
    Follow up
    on Dec 13, 2019
  3. arthurschreiber commented on Jan 3, 2020

    @arthurschreiber
    Collaborator

    I think this was fixed via #1023.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Action RequiredFix in current PR

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions