2 Replies Latest reply on Sep 4, 2013 4:00 PM by TarsolyImre

    OCICollGetElemArray problem

      hi ~~

      i have a problem to use OCICollGetElemArray..


      //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
          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

            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.