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

Interval's day output (format) and milliseconds part (of a value). #363

Open
wiluite opened this issue Sep 17, 2024 · 2 comments
Open

Interval's day output (format) and milliseconds part (of a value). #363

wiluite opened this issue Sep 17, 2024 · 2 comments

Comments

@wiluite
Copy link

wiluite commented Sep 17, 2024

Hello,

Suppose, I have a code:

    try
    {
        const int ArraySize = 5;

        Environment::Initialize();

        Connection con(otext("//localhost:1521/xepdb1"), otext("user1"), otext("password1"));

        std::vector<Interval> ivals;

        Statement st(con);
        st.Execute(otext("create table products1 (ival INTERVAL DAY TO SECOND)"));

        st.Prepare(otext("insert into products1 values(:ivals)"));
        st.SetBindArraySize(ArraySize);
        st.Bind(otext(":ivals"), ivals, Interval::DaySecond, BindInfo::In);

        Interval iv (Interval::DaySecond);
        iv.SetDay(1);
        iv.SetHours(14);
        iv.SetMinutes(54);
        iv.SetSeconds(1);
        iv.SetMilliSeconds(130);
        for (int i = 0; i< ArraySize; i++)
        {
            ivals.push_back(iv);
        }

        st.ExecutePrepared();
        con.Commit();

        st.Execute("select * from products1");
        Resultset rs = st.GetResultset();
        while (rs++)
        {
            std::cout << rs.Get<Interval>(1) << std::endl;
        }
        // st.Execute("drop table products1");

    }
    catch (std::exception &ex)
    {
        std::cout << ex.what() << std::endl;
    }
    Environment::Cleanup();

And I have the output as a result set:

+001 14:54:01.000
+001 14:54:01.000
+001 14:54:01.000
+001 14:54:01.000
+001 14:54:01.000

In the Oracle SQL Developer the command desc products1;
shows the following:

Name Null? Type


IVAL INTERVAL DAY(2) TO SECOND(6)

So, I probably should see:

+01 14:54:01.130
+01 14:54:01.130
+01 14:54:01.130
+01 14:54:01.130
+01 14:54:01.130

I am somehow loosing milliseconds.
Can you hint what is wrong with my code?

Thanks.

p.s.
In Oracle SQL Developer I do not see milliseconds as well, but I do see +xx format of the days.

@wiluite
Copy link
Author

wiluite commented Sep 24, 2024

As to the second phrase of the topic: I've understood that any references to "Milliseconds" (and correspoding API names) in the Interval type documentation should be read as "Nanoseconds", according to Oracle documentation.

Thanks.

@vrogier vrogier self-assigned this Sep 30, 2024
vrogier pushed a commit that referenced this issue Sep 30, 2024
@vrogier
Copy link
Owner

vrogier commented Sep 30, 2024

Hi,

Thanks for reporting this !
In older Oracle versions, OCI documentation for OCIIntervalGetDaySecond() and OCIIntervalSetDaySecondl() refered to 'fractional part of second' and not "nanoseconds" in more recent ones.

Thus :

  • I updated documentation of the C and C++ APIs to precise it is nano seconds (no code change in C API)
  • I added Interval::GetNanoSeconds() and Interval::SetNanoSeconds() that behave as previous Inverval::GetMilliSeconds() and Inverval::SetMilliSeconds()
  • I modified Inverval::GetMilliSeconds() and Inverval::SetMilliSeconds() with a multiplier and divider factor

Regards,

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

2 participants