Example for Lookup Service Provider with a Hash Lookup.
int iSvcToken;
short sMethod;
char Line[INPUT_LINE_MAX_SIZE];
int *piRows = NULL;
int i = 0;
int j = 0;
int iLen = 0;
int iCnt = 0;
FILE *fin = NULL;
char PrvName[] = "LKP";
#ifndef USE_ODPP_MBCS_CHAR_CALLS
ODPP_WCHAR LdsId[] = L"EMP_LKP";
ODPP_WCHAR ConnStr[] = L"SAMPLE";
ODPP_WCHAR LDSSchema[] = L"ODPP";
ODPP_WCHAR SearchCols[] = L"EMPNONUM, FIRSTNME"
ODPP_WCHAR ReplaceCols[] = L"LASTNAME, HIREDATE, SALARY"
#else
char LdsId[] = "EMP_LKP";
char ConnStr[] = "SAMPLE";
char LDSSchema[] = "ODPP";
char SearchCols[] = "EMPNONUM, FIRSTNME"
char ReplaceCols[] = "LASTNAME, HIREDATE, SALARY"
#endif
memset(InitParameters, 0, PARAMETER_MAX_SIZE *
sizeof(
DP_INIT_OP_DEF));
for(iTempCnt=0; iTempCnt < MAX_COLUMNS; iTempCnt++)
{
}
for(iTempCnt=0; iTempCnt < PARAMETER_MAX_SIZE; iTempCnt++)
{
}
SvcDef.pParams = &InitParameters[0];
SvcDef.pFldDef = &FldDef[0];
SvcDef.bCopyToDest = FALSE;
#ifndef USE_ODPP_MBCS_CHAR_CALLS
FldDef[0].cSubType = 'W';
if(NULL == FldDef[0].CN.pWC)
{
printf("\nFailed to allocate pWC struct of DP_FIELD_DEF\n");
goto CleanSvcDef;
}
FldDef[0].iDataCodePage = 0;
FldDef[0].cDataDBMSType = 0;
FldDef[0].iColNameBytes = (MAX_COLNAME_SIZE + 1) * sizeof(ODPP_WCHAR);
FldDef[0].CN.pWC->pColName = (ODPP_WCHAR *) malloc(FldDef[0].iColNameBytes);
if(NULL == FldDef[0].CN.pWC->pColName)
{
printf("\nFailed to allocate memory for Column name\n");
goto CleanSvcDef;
}
memset(FldDef[0].CN.pWC->pColName, 0, FldDef[0].iColNameBytes);
wcscpy(FldDef[0].CN.pWC->pColName, L"EMPNONUM");
FldDef[1].cSubType = 'W';
if(NULL == FldDef[1].CN.pWC)
{
printf("\nFailed to allocate pWC struct of DP_FIELD_DEF\n");
goto CleanSvcDef;
}
FldDef[1].iDataCodePage = 0;
FldDef[1].cDataDBMSType = 0;
FldDef[1].iColNameBytes = (MAX_COLNAME_SIZE + 1) * sizeof(ODPP_WCHAR);
FldDef[1].CN.pWC->pColName = (ODPP_WCHAR *) malloc(FldDef[1].iColNameBytes);
if(NULL == FldDef[1].CN.pWC->pColName)
{
printf("\nFailed to allocate memory for Column name\n");
goto CleanSvcDef;
}
memset(FldDef[1].CN.pWC->pColName, 0, FldDef[1].iColNameBytes);
wcscpy(FldDef[1].CN.pWC->pColName, L"FIRSTNME");
FldDef[2].cSubType = 'W';
if(NULL == FldDef[2].CN.pWC)
{
printf("\nFailed to allocate pWC struct of DP_FIELD_DEF\n");
goto CleanSvcDef;
}
FldDef[2].iDataCodePage = 0;
FldDef[2].cDataDBMSType = 0;
FldDef[2].iColNameBytes = (MAX_COLNAME_SIZE + 1) * sizeof(ODPP_WCHAR);
FldDef[2].CN.pWC->pColName = (ODPP_WCHAR *) malloc(FldDef[2].iColNameBytes);
if(NULL == FldDef[2].CN.pWC->pColName)
{
printf("\nFailed to allocate memory for Column name\n");
goto CleanSvcDef;
}
memset(FldDef[2].CN.pWC->pColName, 0, FldDef[2].iColNameBytes);
wcscpy(FldDef[2].CN.pWC->pColName, L"LASTNAME");
FldDef[3].cSubType = 'W';
if(NULL == FldDef[3].CN.pWC)
{
printf("\nFailed to allocate pWC struct of DP_FIELD_DEF\n");
goto CleanSvcDef;
}
FldDef[3].iDataCodePage = 0;
FldDef[3].cDataDBMSType = 0;
FldDef[3].iColNameBytes = (MAX_COLNAME_SIZE + 1) * sizeof(ODPP_WCHAR);
FldDef[3].CN.pWC->pColName = (ODPP_WCHAR *) malloc(FldDef[3].iColNameBytes);
if(NULL == FldDef[3].CN.pWC->pColName)
{
printf("\nFailed to allocate memory for Column name\n");
goto CleanSvcDef;
}
memset(FldDef[3].CN.pWC->pColName, 0, FldDef[3].iColNameBytes);
wcscpy(FldDef[3].CN.pWC->pColName, L"HIREDATE");
FldDef[4].cSubType = 'W';
if(NULL == FldDef[4].CN.pWC)
{
printf("\nFailed to allocate pWC struct of DP_FIELD_DEF\n");
goto CleanSvcDef;
}
FldDef[4].iDataCodePage = 0;
FldDef[4].cDataDBMSType = 0;
FldDef[4].iColNameBytes = (MAX_COLNAME_SIZE + 1) * sizeof(ODPP_WCHAR);
FldDef[4].CN.pWC->pColName = (ODPP_WCHAR *) malloc(FldDef[4].iColNameBytes);
if(NULL == FldDef[4].CN.pWC->pColName)
{
printf("\nFailed to allocate memory for Column name\n");
goto CleanSvcDef;
}
memset(FldDef[4].CN.pWC->pColName, 0, FldDef[4].iColNameBytes);
wcscpy(FldDef[4].CN.pWC->pColName, L"SALARY");
#else
FldDef[0].cSubType = 'M';
if(NULL == FldDef[0].CN.pMC)
{
printf("\nFailed to allocate pMC struct of DP_FIELD_DEF\n");
return ODPPFAILURE;
}
FldDef[0].iDataCodePage = -1;
FldDef[0].CN.pMC->pColName = (char *) malloc(FldDef[0].iColNameBytes);
if(NULL == FldDef[0].CN.pMC->pColName)
{
printf("\nFailed to allocate memory for Column name\n");
goto CleanSvcDef;
}
memset(FldDef[0].CN.pMC->pColName, 0, FldDef[0].iColNameBytes);
strcpy(FldDef[0].CN.pMC->pColName, "EMPNONUM");
FldDef[1].cSubType = 'M';
if(NULL == FldDef[1].CN.pMC)
{
printf("\nFailed to allocate pMC struct of DP_FIELD_DEF\n");
goto CleanSvcDef;
}
FldDef[1].iDataCodePage = -1;
FldDef[1].CN.pMC->pColName = (char *) malloc(FldDef[1].iColNameBytes);
if(NULL == FldDef[1].CN.pMC->pColName)
{
printf("\nFailed to allocate memory for Column name\n");
goto CleanSvcDef;
}
memset(FldDef[1].CN.pMC->pColName, 0, FldDef[1].iColNameBytes);
strcpy(FldDef[1].CN.pMC->pColName, "FIRSTNME");
FldDef[2].cSubType = 'M';
if(NULL == FldDef[2].CN.pMC)
{
printf("\nFailed to allocate pMC struct of DP_FIELD_DEF\n");
goto CleanSvcDef;
}
FldDef[2].iDataCodePage = -1;
FldDef[2].CN.pMC->pColName = (char *) malloc(FldDef[2].iColNameBytes);
if(NULL == FldDef[2].CN.pMC->pColName)
{
printf("\nFailed to allocate memory for Column name\n");
goto CleanSvcDef;
}
memset(FldDef[2].CN.pMC->pColName, 0, FldDef[2].iColNameBytes);
strcpy(FldDef[2].CN.pMC->pColName, "LASTNAME");
FldDef[3].cSubType = 'M';
if(NULL == FldDef[3].CN.pMC)
{
printf("\nFailed to allocate pMC struct of DP_FIELD_DEF\n");
goto CleanSvcDef;
}
FldDef[3].iDataCodePage = -1;
FldDef[3].CN.pMC->pColName = (char *) malloc(FldDef[3].iColNameBytes);
if(NULL == FldDef[3].CN.pMC->pColName)
{
printf("\nFailed to allocate memory for Column name\n");
goto CleanSvcDef;
}
memset(FldDef[3].CN.pMC->pColName, 0, FldDef[3].iColNameBytes);
strcpy(FldDef[3].CN.pMC->pColName, "HIREDATE");
FldDef[4].cSubType = 'M';
if(NULL == FldDef[4].CN.pMC)
{
printf("\nFailed to allocate pMC struct of DP_FIELD_DEF\n");
goto CleanSvcDef;
}
FldDef[4].iDataCodePage = -1;
FldDef[4].CN.pMC->pColName = (char *) malloc(FldDef[4].iColNameBytes);
if(NULL == FldDef[4].CN.pMC->pColName)
{
printf("\nFailed to allocate memory for Column name\n");
goto CleanSvcDef;
}
memset(FldDef[4].CN.pMC->pColName, 0, FldDef[4].iColNameBytes);
strcpy(FldDef[4].CN.pMC->pColName, "SALARY");
#endif
#ifndef USE_ODPP_MBCS_CHAR_CALLS
if(NULL == InitParameters[1].PV.pWC)
{
printf("Failed to allocate memory for pWC->DPPRM_VAL_WC_SS");
goto CleanSvcDef;
}
iLen = wcslen(SearchCols);
InitParameters[1].iValueBufBytes = (iLen + 1) * sizeof(ODPP_WCHAR);
InitParameters[1].PV.pWC->pParamVal = (ODPP_WCHAR *) malloc(InitParameters[1].iValueBufBytes);
if(NULL == InitParameters[1].PV.pWC->pParamVal)
{
printf("Failed to allocate memory for parameter value pParamVal");
goto CleanSvcDef;
}
memset(InitParameters[1].PV.pWC->pParamVal, 0, (iLen +1));
wcsncpy(InitParameters[1].PV.pWC->pParamVal, SearchCols, iLen);
InitParameters[1].PV.pWC->pParamVal[iLen] = '\0';
if(NULL == InitParameters[2].PV.pWC)
{
printf("Failed to allocate memory for pWC->DPPRM_VAL_WC_SS");
goto CleanSvcDef;
}
iLen = wcslen(ReplaceCols);
InitParameters[2].iValueBufBytes = (iLen + 1) * sizeof(ODPP_WCHAR);
InitParameters[2].PV.pWC->pParamVal = (ODPP_WCHAR *) malloc(InitParameters[2].iValueBufBytes);
if(NULL == InitParameters[2].PV.pWC->pParamVal)
{
printf("Failed to allocate memory for parameter value pParamVal");
goto CleanSvcDef;
}
memset(InitParameters[2].PV.pWC->pParamVal, 0, (iLen+1));
wcsncpy(InitParameters[2].PV.pWC->pParamVal, ReplaceCols, iLen);
InitParameters[2].PV.pWC->pParamVal[iLen] = '\0';
if(NULL == InitParameters[3].PV.pWC)
{
printf("Failed to allocate memory for pWC->DPPRM_VAL_WC_SS");
goto CleanSvcDef;
}
iLen = wcslen(LdsId);
InitParameters[3].iValueBufBytes = (iLen + 1) * sizeof(ODPP_WCHAR);
InitParameters[3].PV.pWC->pParamVal = (ODPP_WCHAR *) malloc(InitParameters[3].iValueBufBytes);
if(NULL == InitParameters[3].PV.pWC->pParamVal)
{
printf("Failed to allocate memory for parameter value pParamVal");
goto CleanSvcDef;
}
memset(InitParameters[3].PV.pWC->pParamVal, 0, (iLen+1));
wcsncpy(InitParameters[3].PV.pWC->pParamVal, LdsId, iLen);
InitParameters[3].PV.pWC->pParamVal[iLen] = '\0';
if(NULL == InitParameters[4].PV.pWC)
{
printf("Failed to allocate memory for pWC->DPPRM_VAL_WC_SS");
goto CleanSvcDef;
}
iLen = wcslen(ConnStr);
InitParameters[4].iValueBufBytes = (iLen + 1) * sizeof(ODPP_WCHAR);
InitParameters[4].PV.pWC->pParamVal = (ODPP_WCHAR *) malloc(InitParameters[4].iValueBufBytes);
if(NULL == InitParameters[4].PV.pWC->pParamVal)
{
printf("Failed to allocate memory for parameter value pParamVal");
goto CleanSvcDef;
}
memset(InitParameters[4].PV.pWC->pParamVal, 0, (iLen+1));
wcsncpy(InitParameters[4].PV.pWC->pParamVal, ConnStr, iLen);
InitParameters[4].PV.pWC->pParamVal[iLen] = '\0';
if(NULL == InitParameters[5].PV.pWC)
{
printf("Failed to allocate memory for pWC->DPPRM_VAL_WC_SS");
goto CleanSvcDef;
}
iLen = wcslen(LDSSchema);
InitParameters[5].iValueBufBytes = (iLen + 1) * sizeof(ODPP_WCHAR);
InitParameters[5].PV.pWC->pParamVal = (ODPP_WCHAR *) malloc(InitParameters[5].iValueBufBytes);
if(NULL == InitParameters[5].PV.pWC->pParamVal)
{
printf("Failed to allocate memory for parameter value pParamVal");
goto CleanSvcDef;
}
memset(InitParameters[5].PV.pWC->pParamVal, 0, (iLen+1));
wcsncpy(InitParameters[5].PV.pWC->pParamVal, LDSSchema, iLen);
InitParameters[5].PV.pWC->pParamVal[iLen] = '\0';
#else
if(NULL == InitParameters[1].PV.pMC)
{
printf("Failed to allocate memory for pMC->DPPRM_VAL_MC_SS");
goto CleanSvcDef;
}
iLen = (int)strlen(SearchCols);
InitParameters[1].PV.pMC->pParamVal = (char *) malloc(InitParameters[1].iValueBufBytes);
if(NULL == InitParameters[1].PV.pMC->pParamVal)
{
printf("Failed to allocate memory for parameter value pParamVal");
goto CleanSvcDef;
}
memset(InitParameters[1].PV.pMC->pParamVal, 0, (iLen+1));
strncpy(InitParameters[1].PV.pMC->pParamVal, SearchCols, iLen);
InitParameters[1].PV.pMC->pParamVal[iLen] = '\0';
InitParameters[1].PV.pMC->iParamValCodePage = -1;
InitParameters[1].PV.pMC->cParamValDBMSType =
RDB_NONE;
if(NULL == InitParameters[2].PV.pMC)
{
printf("Failed to allocate memory for pMC->DPPRM_VAL_MC_SS");
goto CleanSvcDef;
}
iLen = (int)strlen(ReplaceCols);
InitParameters[2].PV.pMC->pParamVal = (char *) malloc(InitParameters[2].iValueBufBytes);
if(NULL == InitParameters[2].PV.pMC->pParamVal)
{
printf("Failed to allocate memory for parameter value pParamVal");
goto CleanSvcDef;
}
memset(InitParameters[2].PV.pMC->pParamVal, 0, (iLen+1));
strncpy(InitParameters[2].PV.pMC->pParamVal, ReplaceCols, iLen);
InitParameters[2].PV.pMC->pParamVal[iLen] = '\0';
InitParameters[2].PV.pMC->iParamValCodePage = -1;
InitParameters[2].PV.pMC->cParamValDBMSType =
RDB_NONE;
if(NULL == InitParameters[3].PV.pMC)
{
printf("Failed to allocate memory for pMC->DPPRM_VAL_MC_SS");
goto CleanSvcDef;
}
iLen = (int)strlen(LdsId);
InitParameters[3].PV.pMC->pParamVal = (char *) malloc(InitParameters[3].iValueBufBytes);
if(NULL == InitParameters[3].PV.pMC->pParamVal)
{
printf("Failed to allocate memory for parameter value pParamVal");
goto CleanSvcDef;
}
memset(InitParameters[3].PV.pMC->pParamVal, 0, (iLen+1));
strncpy(InitParameters[3].PV.pMC->pParamVal, LdsId, iLen);
InitParameters[3].PV.pMC->pParamVal[iLen] = '\0';
InitParameters[3].PV.pMC->iParamValCodePage = -1;
InitParameters[3].PV.pMC->cParamValDBMSType =
RDB_NONE;
if(NULL == InitParameters[4].PV.pMC)
{
printf("Failed to allocate memory for pMC->DPPRM_VAL_MC_SS");
goto CleanSvcDef;
}
iLen = (int)strlen(ConnStr);
InitParameters[4].PV.pMC->pParamVal = (char *) malloc(InitParameters[4].iValueBufBytes);
if(NULL == InitParameters[4].PV.pMC->pParamVal)
{
printf("Failed to allocate memory for parameter value pParamVal");
goto CleanSvcDef;
}
memset(InitParameters[4].PV.pMC->pParamVal, 0, (iLen+1));
strncpy(InitParameters[4].PV.pMC->pParamVal, ConnStr, iLen);
InitParameters[4].PV.pMC->pParamVal[iLen] = '\0';
InitParameters[4].PV.pMC->iParamValCodePage = -1;
InitParameters[4].PV.pMC->cParamValDBMSType =
RDB_NONE;
if(NULL == InitParameters[5].PV.pMC)
{
printf("Failed to allocate memory for pMC->DPPRM_VAL_MC_SS");
goto CleanSvcDef;
}
iLen = (int)strlen(LDSSchema);
InitParameters[5].PV.pMC->pParamVal = (char *) malloc(InitParameters[5].iValueBufBytes);
if(NULL == InitParameters[5].PV.pMC->pParamVal)
{
printf("Failed to allocate memory for parameter value pParamVal");
goto CleanSvcDef;
}
memset(InitParameters[5].PV.pMC->pParamVal, 0, (iLen+1));
strncpy(InitParameters[5].PV.pMC->pParamVal, LDSSchema, iLen);
InitParameters[5].PV.pMC->pParamVal[iLen] = '\0';
InitParameters[5].PV.pMC->iParamValCodePage = -1;
InitParameters[5].PV.pMC->cParamValDBMSType =
RDB_NONE;
#endif
SvcDef.sOprCount = 9;
retVal =
Provider_Init(&iSvcToken, &PrvName[0], strlen(PrvName), &SvcDef, FALSE);
if(ODPPSUCCESS != retVal)
{
printf("Provider Init Failed Err=%#x", retVal);
goto CleanSvcDef;
}
Loop through each line of the source CSV file creating the field data for each row.
Loop BEGIN
Here the rowSet is created as a List of rows and not as an Array. An application can also allocate a fixed size array of DP_ROW_DEF structures, fill it with data and pass it to Provider_Service.
After the rowSet has been created invoke the Service Provider to mask the source data
Free the memory that has been allocated if an error occured.