Optim Data Privacy Providers  11.3.0
 All Data Structures Files Functions Variables Macros Groups Pages

In the following example, all the errors are reported in a loop.

RETVAL retVal; //return code
int iErrAreaLen; //Length of error control block storage area
short sErrCnt = 0; //Error count
short i = 0; //Counter
DP_ERR_MSG ErrMsg; //Error message definition
DP_ECB *pEcb = NULL; //Pointer to DP_ECB structure
#ifndef USE_ODPP_MBCS_CHAR_CALLS
ODPP_WCHAR ErrMsgSrc[ODPP_MAX_ERR_MSG_SRC_LENGTH + 1]; //To hold source of formatted error message in wide character(Unicode) format
ODPP_WCHAR ErrMsgText[ODPP_MAX_ERR_MSG_TEXT_LENGTH + 1]; //To hold formatted error message text in wide character(Unicode) format
ODPP_WCHAR ErrMsgBody[ODPP_MAX_ERR_MSG_BODY_LENGTH + 1]; //To hold formatted error message body in wide character( Unicode) format
#else
char ErrMsgSrc[ODPP_MAX_ERR_MSG_SRC_LENGTH + 1]; //To hold source of formatted error message in mixed character(MBCS/SBCS) format
char ErrMsgText[ODPP_MAX_ERR_MSG_TEXT_LENGTH + 1]; //To hold formatted error message text in mixed character (MBCS/SBCS) format
char ErrMsgBody[ODPP_MAX_ERR_MSG_BODY_LENGTH + 1]; //To hold formatted error message body in mixed character (MBCS/SBCS) format
#endif
//Clear the DP_ERR_MSG structure memory
memset(&ErrMsg, 0, sizeof(DP_ERR_MSG));
//Initialize the DP_ERR_MSG structure
//Retrieve the number of errors that have occurred and the size of the ECB storage area
retVal = Provider_GetErrorCount(iSvcToken, &sErrCnt, &iErrAreaLen);
if(ODPPSUCCESS != retVal)
{
printf("Failed to get the Error Count, Err=%#x", retVal);
return retVal;
}
if(sErrCnt <= 0)
{
printf("\nNo Error Detected\n");
return ODPPSUCCESS;
}
printf("\nTotal Error Count = %d\n", sErrCnt);
//Now set the required fields of DP_ERR_MSG
//Language to use to return the error message. Currently not used and zero must be supplied.
ErrMsg.iLanguage = 0;
//Allocate the ODPP error control block
pEcb = (DP_ECB*)malloc(iErrAreaLen);
if(NULL == pEcb)
{
printf("Error Block Malloc failed\n");
goto OnErrorClean;
}
memset(pEcb, 0, iErrAreaLen);
//Initialize the DP_ECB structure
//Allocate ODPP error message block
#ifndef USE_ODPP_MBCS_CHAR_CALLS
//For wide character (Unicode) format
//Set the subtype of DP_ERR_MSG to 'W' to retrieve formatted error message in wide character(Unicode) format
ErrMsg.cSubType = 'W';
//Allocate memory for error message block
ErrMsg.EM.pWC = (DPEM_WC_SS *) malloc(sizeof(DPEM_WC_SS));
if(NULL == ErrMsg.EM.pWC)
{
printf("\nMem Alloc failed for DPEM_WC_SS \n");
goto OnErrorClean;
}
memset(ErrMsg.EM.pWC, 0, sizeof(DPEM_WC_SS));
//pMsgSrc will hold the source of the error message in wide character (Unicode) format
ErrMsg.EM.pWC->pMsgSrc = &ErrMsgSrc[0];
//Set the size of the buffer ErrMsgSrc, in bytes
ErrMsg.EM.pWC->iMsgSrcBytes = sizeof(ErrMsgSrc);
//pMsg will hold the error message text in wide character (Unicode) format
ErrMsg.EM.pWC->pMsg = &ErrMsgText[0];
//Set the size of the buffer ErrMsgText, in bytes
ErrMsg.EM.pWC->iMsgBytes = sizeof(ErrMsgText);
//pMsgBody will hold the error message description in details in wide character (Unicode) format
ErrMsg.EM.pWC->pMsgBody = &ErrMsgBody[0];
//Set the size of the buffer ErrMsgBody, in bytes
ErrMsg.EM.pWC->iMsgBodyBytes = sizeof(ErrMsgBody);
#else
//For mixed character (MBCS/SBCS) format
//Set the subtype of DP_ERR_MSG to 'M' to retrieve formatted error message in mixed character(MBCS/SBCS) format
ErrMsg.cSubType = 'M';
//Allocate memory for error message block
ErrMsg.EM.pMC = (DPEM_MC_SS *) malloc(sizeof(DPEM_MC_SS));
if(NULL == ErrMsg.EM.pMC)
{
printf("\nMem Alloc failed for DPEM_MC_SS \n");
goto OnErrorClean;
}
memset(ErrMsg.EM.pMC, 0, sizeof(DPEM_MC_SS));
//pMsgSrc will hold the source of the error message in mixed character (MBCS/SBCS) format
ErrMsg.EM.pMC->pMsgSrc = &ErrMsgSrc[0];
//Set the size of the buffer ErrMsgSrc, in bytes
ErrMsg.EM.pMC->iMsgSrcBytes = sizeof(ErrMsgSrc);
//pMsg will hold the error message text in mixed character (MBCS/SBCS) format
ErrMsg.EM.pMC->pMsg = &ErrMsgText[0];
//Set the size of the buffer ErrMsgText, in bytes
ErrMsg.EM.pMC->iMsgBytes = sizeof(ErrMsgText);
//pMsgBody will hold the erroe message description in details in mixed character (MBCS/SBCS) format
ErrMsg.EM.pMC->pMsgBody = &ErrMsgBody[0];
//Set the size of the buffer ErrMsgBody, in bytes
ErrMsg.EM.pMC->iMsgBodyBytes = sizeof(ErrMsgBody);
//For system default codepage
ErrMsg.EM.pMC->iEMCodePage = -1;
//DBMS Type code
ErrMsg.EM.pMC->cEMDBMSType = RDB_NONE;
#endif
//Loop through number of error count and print the formatted error messages
for ( short i = 0; i < sErrCnt; i++ )
{
//Call this function to get the oldest ECB
retVal = Provider_GetError(iSvcToken, pEcb);
printf("\nRow Number: %d\n",(int)pEcb->iRowNum);
printf("Error Code: %d\t",pEcb->iErrCode);
printf("Token Count: %d\t\n",pEcb->sNumTokens);
//Clear the error message source, text and body buffers
memset(ErrMsgSrc,'\0',sizeof(ErrMsgSrc));
memset(ErrMsgText,'\0',sizeof(ErrMsgText));
memset(ErrMsgBody,'\0',sizeof(ErrMsgBody));
//Assign the error control block populated in call to Provider_GetError()
ErrMsg.pECB = pEcb;
//Retrieve the number of errors that have occurred and the size of the ECB storage area
retVal = Provider_GetFormattedErrorMsg(&ErrMsg);
if(retVal != ODPPSUCCESS)
{
printf("Error Code not found, Err = %#x\n",retVal);
continue;
}
#ifndef USE_ODPP_MBCS_CHAR_CALLS
printf("Error Message Source:%ws\n",ErrMsgSrc);
printf("Error Message Text: %ws \n",ErrMsgText);
printf("Error Message Body: \n%ws\n",ErrMsgBody);
#else
printf("Error Message Source:%s\n",ErrMsgSrc);
printf("Error Message Text: %s \n",ErrMsgText);
printf("Error Message Body: \n %s\n",ErrMsgBody);
#endif
}
//Release all ECB storage areas from errors not retrieved
retVal = Provider_TermErrors(iSvcToken);
if(retVal != ODPPSUCCESS)
{
printf("Provider_TermErrors failed, Err = %#x\n",retVal);
return retVal;
}

Free the memory allocated.

OnErrorClean:
if(NULL != pEcb)
free(pEcb);
#ifndef USE_ODPP_MBCS_CHAR_CALLS
if(NULL != ErrMsg.EM.pWC)
free(ErrMsg.EM.pWC);
#else
if(NULL != ErrMsg.EM.pMC)
free(ErrMsg.EM.pMC);
#endif
return retVal;