vrogier / ocilib

OCILIB (C and C++ Drivers for Oracle) - Open source C and C++ library for accessing Oracle databases
http://www.ocilib.net
Apache License 2.0
325 stars 119 forks source link

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

Open wiluite opened 2 months ago

wiluite commented 2 months ago

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 commented 2 months ago

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 commented 2 months ago

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 :

Regards,