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

Wrong date saving when object used #1532

Open
yakov-rs opened this issue Nov 18, 2022 · 5 comments
Open

Wrong date saving when object used #1532

yakov-rs opened this issue Nov 18, 2022 · 5 comments

Comments

@yakov-rs
Copy link

  1. What versions are you using?
    database: 18c

    process.platform - win32
    process.version - v14.16.0
    process.arch - x64
    require('oracledb').versionString - 5.5.0
    require('oracledb').oracleClientVersionString - 19.14.0.0.0

  2. Is it an error or a hang or a crash?
    error

  3. What error(s) or behavior you are seeing?

wrong time in date

  1. Include a runnable Node.js script that shows the problem.

`

process.env.TZ='Europe/Moscow';
process.env.ORA_SDTZ='Europe/Moscow';
const oracledb = require('oracledb');

async function execute() {
    let connection;

    let opts = { autoCommit: true };
    let value = '2022-11-17T18:47:40+03:00';
    let result;

    try {
	    connection = await oracledb.getConnection({
		    user: "YOUR_USERNAME",
		    password: 'YOUR_PASSWORD',
		    connectString: "YOUR_CONNECTION_STRING"
	    });

	    await connection.execute("insert into test_save_date_from_node(dt, source) values (:dt, 'insert')",
		    {
			    dt: {
				    val: new Date(value),
				    type: oracledb.DATE,
				    dir: oracledb.BIND_IN
			    }
		    },
		    opts);

	    const ClassName = await connection.getDbObjectClass('TEST_SAVE_DATE_FROM_NODE_REC');
	    await connection.execute("begin test_save_date_from_node_prc(p_rec => :p_rec); end;",
		    {
			    p_rec: {
				    val: { DT: new Date(value) },
				    type: ClassName,
				    dir: oracledb.BIND_IN
			    }
		    },
		    opts);

	    result = await connection.execute("SELECT dt FROM test_save_date_from_node");
	    result.rows.forEach(item => console.log(new Date(item).toLocaleString()));

    } catch (err) {
	    console.error(err);
    } finally {
	    if (connection) {
		    try {
			    await connection.close();
		    } catch (err) {
			    console.error(err);
		    }
	    }
    }


}

execute();

`

In database:

`

create table test_save_date_from_node(
  dt date,
  source varchar2(10 char)
);

create type test_save_date_from_node_rec is object (
  dt date
);

create or replace procedure test_save_date_from_node_prc(
  p_rec test_save_date_from_node_rec
)
as
begin
  insert into test_save_date_from_node(dt, source) values (p_rec.dt, 'type');
end;

`

result:

`

17.11.2022 18:47:40	insert
17.11.2022 15:47:40	type

`

`

SELECT DBTIMEZONE FROM DUAL;

Europe/Moscow

`

Please help me to understand, it's error or I did something wrong?

@yakov-rs yakov-rs added the bug label Nov 18, 2022
@abrar-khan007
Copy link

Try date using interface

@yakov-rs
Copy link
Author

@abrar-khan007 Could you be more specific and show me how can I do it?

@cjbj
Copy link
Member

cjbj commented Nov 21, 2022

See #1340 (comment)

@yakov-rs
Copy link
Author

@cjbj ok, txs
If I create type like this:

create type test_save_date_from_node_rec is object ( dt timestamp with local time zone );

and other code would stay as it was before (type of field in table - date), then result will be correct.

@cjbj tell me please can you see that it could be correct workaround?

@abrar-khan007
Copy link

@abrar-khan007 Could you be more specific and show me how can I do it?

Have u checked for null , I believe default format is getting executed . Using interface provide value be specific for conversation

@cjbj cjbj added enhancement and removed bug labels Nov 23, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants