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

problem about OCI_ElemInit() #2

Closed
weexp opened this issue Jun 30, 2015 · 3 comments
Closed

problem about OCI_ElemInit() #2

weexp opened this issue Jun 30, 2015 · 3 comments
Assignees

Comments

@weexp
Copy link

weexp commented Jun 30, 2015

Hi,vrogier
IN the lastest version , OCI_IterFree() now works well, and the memory retention problem has been resolved, thanks for your excellent work!
But now, I have anothoer problem. I use OCI_ElemSetDouble() function,and then I use OCI_CollGetElem() and OCI_ElemGetDouble() to get the value of element, the result is wrong.
My test code like this:

void testocilib(std::string dburl, std::string username, std::string password, std::string tablename)
{
OCI_Connection *cn;
OCI_Statement *st;
OCI_Coll *coll_ord;
OCI_Elem *elem_ord;
OCI_TypeInfo *tif_ord;
int i;
int elemnum = 4;

int isSus = OCI_Initialize(0, 0, OCI_ENV_CONTEXT);
cn = OCI_ConnectionCreate(dburl.c_str(), username.c_str(), password.c_str(), OCI_SESSION_DEFAULT);
st = OCI_StatementCreate(cn);

/* retreive type info */
tif_ord = OCI_TypeInfoGet(cn, "MDSYS.SDO_ORDINATE_ARRAY", OCI_TIF_TYPE);

/* create sub arrays */
coll_ord = OCI_CollCreate(tif_ord);

/* create sub array element accessors */
elem_ord = OCI_ElemCreate(tif_ord);


/* build ordinates collection with test values */
for (i = 0; i < elemnum; i++)
{
    OCI_ElemSetDouble(elem_ord, ((double) i + 0.123456));
    OCI_CollAppend(coll_ord, elem_ord);
    OCI_ElemSetDouble(elem_ord, ((double) i + 0.789000));
    OCI_CollAppend(coll_ord, elem_ord);
}


for (i = 1; i <= OCI_CollGetSize(coll_ord);i++)
{
    OCI_Elem* cur_elem = OCI_CollGetElem(coll_ord,i);
    double elem_value = OCI_ElemGetDouble(cur_elem);
    printf("The %d Elem is %lf\n",i,elem_value);
}

/* free local objects */
OCI_CollFree(coll_ord);
OCI_ElemFree(elem_ord);

//statement
if (0 != st)
{
    OCI_StatementFree(st);
    st = 0;
}
//connection
if (0 != cn)
{
    OCI_ConnectionFree(cn);
    cn = 0;
}
OCI_Cleanup();

}

the output is : all elements are zero!
My platform is VS2010, Oracle 11g, OCI_CHARSET_ANSI.
I check the element.c file , I found that : In the lastest release version, in element.c file, OCI_ElemInit has been modified, the code
case OCI_CDT_NUMERIC:
{
if (!elem->handle)
{
elem->handle = (OCINumber *) OCI_MemAlloc(OCI_IPC_VOID, sizeof(OCINumber), 1, TRUE);
}
break;
}
has been commented out,
and in OCI_ElemFree():

if ((OCI_OBJECT_ALLOCATED == elem->hstate) && (OCI_CDT_NUMERIC == elem->typinf->cols[0].datatype))
{
    OCI_FREE(elem->handle)
}

has also been commented out.
I add the two section of codes in the element.c again, and now the result is correct.

So , I think these two sections of code should not been commented out.
Would you check the element.c again? Thanks!

@vrogier
Copy link
Owner

vrogier commented Jun 30, 2015

Hi,

Thanks again.

I've committed a new fix for it.

@vrogier
Copy link
Owner

vrogier commented Jun 30, 2015

By the way, i see that you're coding in C++.

Here is your sample function rewritten using the OCILIB C++ API:

        Environment::Initialize();

        Connection cn("db12c", "usr", "pwd");
        Statement st(cn);        
        Collection<double> coll(TypeInfo(cn, "MDSYS.SDO_ORDINATE_ARRAY", TypeInfo::Type));

        for (int i = 0; i < 4; i++)
        {
            coll.Append((double)i + 0.123456);
            coll.Append((double)i + 0.789000);
        }

        for (unsigned int i = 1, n = coll.GetSize(); i <= n; i++)
        {
            cout << "The " << i << " Elem is " << static_cast<double>(coll[i]) << endl;
        }

Much simpler and more compact :)

@weexp
Copy link
Author

weexp commented Jul 1, 2015

Thanks! I'll try to use the C++ API.

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