This discussion is archived
2 Replies Latest reply: Sep 4, 2013 9:00 AM by TarsolyImre RSS

OCICollGetElemArray problem

903046 Newbie
Currently Being Moderated
hi ~~

i have a problem to use OCICollGetElemArray..

source---

//nOrdsCount == 33000
// OCIArray* pSdoGeom->sdo_ordinates .

     r = OCICollSize(m_pConnection->m_hEnv, m_pConnection->m_hError, (OCIColl *)(pSdoGeom->sdo_ordinates), &nOrdsCount);
     sb4 nIndex = 0;
     uword nCount = nOrdsCount;
     OCINumber **ppNumbers = new OCINumber*[nCount];
     memset(ppNumbers, 0, sizeof(OCINumber)*(nCount));
     exists = 0;

     r = OCICollGetElemArray(hEnv, hError, (const OCIColl *)pSdoGeom->sdo_ordinates, (sb4)nIndex,
          (boolean *)&exists, (void**)ppNumbers, (void**)0, &nCount);
     if(checkerr(m_pConnection->m_hError, r, m_pConnection->m_szErrbuf, m_pConnection->m_sb4ErrorCode)) {
          delete pDestPolygon;
          delete []ppNumbers;
          return NULL;
     }

     double          *pDoubleVals = new double[nCount];
     memset(pDoubleVals, 0, sizeof(double)*nCount);
     
     r = OCINumberToRealArray(m_pConnection->m_hError, (const OCINumber**)ppNumbers, nCount, sizeof(double), pDoubleVals);
     
     if(checkerr(m_pConnection->m_hError, r, m_pConnection->m_szErrbuf, m_pConnection->m_sb4ErrorCode)) {
          delete pDestPolygon;
          delete []ppNumbers;
          delete []pDoubleVals;
          return NULL;
     }
--

when i call OCICollGetElemArray Access violation is occured..
dose anyone know why...
  • 1. Re: OCICollGetElemArray problem
    ddevienne Newbie
    Currently Being Moderated
    Just guessing here...

    You used OCICollSize(m_pConnection->m_hEnv, m_pConnection->m_hError, ...) but OCICollGetElemArray(hEnv, hError, ...). Could it be that hEnv and/or hError areuninitialized variables, unlike m_pConnection->m_hEnv and m_pConnection->m_hError?

    I know one often reformats actual code when posting it, so maybe that's nothing, but just in case.

    In general avoid C-casts (which are even stronger than reinterpret_cast<>), and don't cast unless you really need it (I see unnecessary ones), to ensure you are really using the correct types. Otherwise it's just too easy to crash with OCI IMHO. --DD                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                       
  • 2. Re: OCICollGetElemArray problem
    TarsolyImre Newbie
    Currently Being Moderated

    Well, some minutes before I have the same problem, but I realised, I missed the types.

    Your code seems correct, but we cannot see the type of variable exists. It seems to boolean, but it should be boolean*, and point to an allocated nCount sized buffer.

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points