tediousjs / tedious

Node TDS module for connecting to SQL Server databases.

Home Page:http://tediousjs.github.io/tedious/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

useUTC on Insert and Select

shiroze opened this issue · comments

Software versions

  • Tedious: 15.1.3
  • SQL Server: 2016
  • Node.js: 18.10.0
  • node-mssql: 9.1.1

Connection configuration

const config = {
  server: 'MYSERVER',
  authentication: {
    type: "default",
    options: {
      userName: "db",
      password: "db@123"
    }
  },
  options: {
    useUTC: false,
    database: 'db_dev',
    encrypt: true,
    trustServerCertificate: true,
  },
};

Detail Reference is here Node-issue

Hi @shiroze, just to make sure is this kind the query that you try to execute ?

function inputParameters() {
  // Values contain variables idicated by '@' sign
  const sql = `Insert into MyTable ( test_c3) VALUES (@time)`;
  const request = new Request(sql, (err, rowCount) => {
    if (err) {
      throw err;
    }

    console.log('rowCount: ', rowCount);
    console.log('input parameters success!');
  });

  // Setting values to the variables. Note: first argument matches name of variable above.
  request.addParameter('time', TYPES.DateTime, '2023-03-16 11:58:30');

  connection.execSql(request);
}

And you question is why the without set useUTC to false you get a different time?
If I got your question right and the example that I put above if what your trying to do, then I can explain why the behavior is expected:
On tedious side, our useUTC setting is default to true. Unfortunately, if you want to disable UTC, you have to explicitly set it to false in the configuration. Hope this answers' your question.

Yes, When doing insert with useUTC:false I got the correct time 2023-03-16 11:58:30 but when I select that data it return the UTC time 2023-03-16 04:58:30

Hi @shiroze , Thanks for the reply and I am able to reproduce this behavior. Will keep investigating, and see if I can come up with a fix.

Hi @shiroze , Thanks for the reply and I am able to reproduce this behavior. Will keep investigating, and see if I can come up with a fix.

Hi @MichaelSun90 , Thank you hope this Bug can be Fixed ASAP.
Thank you for the reply

Hi @MichaelSun90, I do have the same problem as @shiroze . waiting for the feedback...

Hi @nanjarapalli , we were looking into this #1467 , and this suppose to provide a better date time types support. Will continue working on this when we got the bandwidth, and update you guys if we make any progress.