Skip to Main Content

DevOps, CI/CD and Automation

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Breaking out of a piecewise fetch

109884Apr 1 2002
I have an application that does a piecewise fetch using OCIStmtGetPieceInfo/OCIStmtSetPieceInfo to retrieve a SQLT_LBI column. Code is similar to that found in the OCI programmers reference and works without error.

I also need to be able to move to the next row in my result set without fetching the entire long raw column in the current row. I have not been able to find a documented way to do this. Does anyone know of a way to do this?


I've been experimenting with the following code...


HRESULT ClosePieceFetch()
{
UTL__PublicFunction;
sword nRet;

OCIDefine* phandleDefine;
ub4 nType;
ub1 paramIO;
ub4 nRow;
ub4 nElement;
ub1 piece;

ub4 cbData;
// byte rgData[1];
byte rgData[4096];

do
{
nRet = COracle::OCIStmtGetPieceInfo(m_handleStmt, m_pSession->m_handleError, reinterpret_cast<dvoid**>(&phandleDefine), &nType, &paramIO, &nRow, &nElement, &piece);
UTL__HrOCICheckReturn(m_pSession->m_handleError, nRet);

if (OCI_HTYPE_DEFINE!=nType)
return UTL__HrMark(E_UNEXPECTED);

// if (phandleDefine!=m_rghandleDefine[iColumn])
// return UTL__HrMark(E_UNEXPECTED);

if (paramIO!=OCI_PARAM_OUT)
return UTL__HrMark(E_UNEXPECTED);

if (0!=nRow)
return UTL__HrMark(E_UNEXPECTED);

if (0!=nElement)
return UTL__HrMark(E_UNEXPECTED);

// docs say the size of the final fetch must be exactly the size of the last remaining piece. they don't say how to cancel a piece fetch but
// it seems that there must be a way since the ODBC & OLEDB drivers allow it. One difference is that these seem to use the older LDA-based OCI
// calls. when we get it wrong OCIStmtFetch2 calls cexit so the application gets killed. have also seen stack corruption with OCI_ONE_PIECE
// it might be be using the defined buffer size and not the one specified here. bumping rgData up to 4096 bytes has helped still I suspect this
// think might also corrupt the stack on a larger long raw. 4/2/02 RS

// piece = OCI_LAST_PIECE;
// cbData = sizeof(rgData);
piece = OCI_ONE_PIECE;
cbData = 1;

nRet = COracle::OCIStmtSetPieceInfo(phandleDefine, OCI_HTYPE_DEFINE, m_pSession->m_handleError, reinterpret_cast<dvoid*>(rgData), &cbData, piece, 0, 0);
UTL__HrOCICheckReturn(m_pSession->m_handleError, nRet);

nRet = COracle::OCIStmtFetch2(m_handleStmt, m_pSession->m_handleError, 1, OCI_FETCH_NEXT, 0, OCI_DEFAULT);
}
while (OCI_NEED_DATA==nRet);

m_bActivePieceFetch = false;

// ignore nRet [generally OCI_ERROR, OCIErrorGet shows ORA-01406]
return S_OK;
}
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Apr 30 2002
Added on Apr 1 2002
3 comments
440 views