Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The value of a Date type field is shared by multiple records. (With Oracle Client) #6056

Open
TeruyukiMatsuzaki opened this issue Apr 16, 2024 · 0 comments

Comments

@TeruyukiMatsuzaki
Copy link

TeruyukiMatsuzaki commented Apr 16, 2024

Environment

Knex version: knex@2.5.1 (npm)
Database + version: Oracle 12 + Oracle Instant Client 21.11 + oracledb@6.2.0 (npm)
OS: AWS Lambda, Windows, node@v18-lts
@atiertant

Bug

  1. I selected data from a table using Knex raw. In the AWS Lambda environment, I needed to correct JST to UTC. Actual SQL is much more complex. Below is an example code.
const result = await knex.raw<ContractInfo[]>("SELECT DISTINCT NO, DATECOLUMN FROM CONTRACT_TABLE");
  result.forEach((row: ContractInfo) => {
    if (row.DATECOLUMN ) {
      const utc = row.DATECOLUMN ;
      const jst = utc.setHours(utc.getHours() -9);
      row.DATECOLUMN = jst;
    }
  });

For example, when there were 5 rows, the value of the Date type column was updated as shown below.

NO | DATECOLUMN
1 | 2024-03-19T00:00:00.000Z => updated to 2024-03-18T15:00:00.000Z. OK.
2 | 2024-03-19T00:00:00.000Z => updated to 2024-03-18T15:00:00.000Z. OK.
3 | NULL
4 | 2024-03-19T00:00:00.000Z => updated to 2024-03-18T06:00:00.000Z. NG. why ?
5 | 2024-03-19T00:00:00.000Z => updated to 2024-03-18T06:00:00.000Z. NG. why ?

The rows in the 4th and 5th rows refer to the same Date object, so it seems that the -9:00 update was applied twice.
I worked around this bug by copying the Date object and assigning it again. I hope that you will identify the cause of the bug and fix it. thank you.

  1. Error message => No errors.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant