Example code from Memory IP
/************************************************************************
Function: mem_procedure_multiresult_out()
Description: process stored procedure multiresult_out
Return: DAM_SUCCESS on Success
DAM_FAILURE on Failure
************************************************************************/
int mem_procedure_multiresult_out(IP_HDBC hdbc,
DAM_HSTMT hstmt, int iType)
{
MEM_CONN_DA *pConnDA = (MEM_CONN_DA *)hdbc;
MEM_PROC_DA *pProcDA;
int iRetCode;
if (iType == DAM_DSP_INIT) {
XM_Tree *pMemTree;
pMemTree = dam_getMemTree(hstmt);
if(!(pProcDA = (MEM_PROC_DA *)xm_allocItem(pMemTree, sizeof(MEM_PROC_DA), XM_NOFLAGS))) {
return DAM_FAILURE;
}
pProcDA->pConnDA = pConnDA;
pProcDA->dam_hstmt = hstmt;
pProcDA->pMemTree = pMemTree;
dam_describeProcedure(hstmt, pProcDA->sQualifier, pProcDA->sOwner, pProcDA-
sProcName, pProcDA->sUserData);
dam_setIP_hstmt(hstmt, pProcDA);
pProcDA->iCurResultSetNum = 0;
/* get the input parameter info */
{
DAM_HROW hrow;
DAM_HROWELEM hRowElem;
DAM_HCOL hcol;
int iParamNum, iRetCode, iValLen, iXOType, iColumnType;
char *pVal;
hrow = dam_getInputRow(hstmt);
/* Get values of the input parameters */
for (hRowElem = dam_getFirstValueSet(hstmt, hrow), iParamNum=1; hRowElem != NULL;
hRowElem = dam_getNextValueSet(hstmt), iParamNum++) {
hcol = dam_getColToSet(hRowElem);
dam_describeCol(hcol, NULL, NULL, &iXOType, NULL);
dam_describeColDetail(hcol, NULL, NULL, &iColumnType, NULL, NULL, NULL,
NULL);
if (iColumnType != SQL_PARAM_INPUT) continue;
iRetCode = dam_getValueToSet(hRowElem, XO_TYPE_CHAR, (void *)&pVal, &iValLen);
if (iRetCode != DAM_SUCCESS) return DAM_FAILURE;
if (iParamNum == 1) pProcDA->iTotalResultSets = atoi(pVal);
if (iParamNum == 2) pProcDA->iItems = atoi(pVal);
}
}
return DAM_SUCCESS;
}
else if (iType == DAM_DSP_EXECUTE) {
DAM_HCOL hColName, hColId, hColD;
char sName[128], sColName[32];
long lVal;
int iRowCount, iColCount;
DAM_HROW hRow;
pProcDA = dam_getIP_hstmt(hstmt);
hColName = dam_getCol(hstmt, "NAME");
hColId = dam_getCol(hstmt, "ID");
/* build result set */
iRowCount = 0;
while (iRowCount < pProcDA->iItems) {
hRow = dam_allocRow(hstmt);
sprintf(sName, "Name%d-%d", pProcDA->iCurResultSetNum, iRowCount);
lVal = iRowCount;
dam_addValToRow(hstmt, hRow, hColName, XO_TYPE_CHAR, sName, XO_NTS);
dam_addValToRow(hstmt, hRow, hColId, XO_TYPE_INTEGER, &lVal,sizeof(lVal));
for (iColCount = 0; iColCount <= pProcDA->iCurResultSetNum; iColCount++) {
sprintf(sColName, "D%d", iColCount);
hColD = dam_getCol(hstmt, sColName);
lVal = iColCount;
dam_addValToRow(hstmt, hRow, hColD, XO_TYPE_INTEGER, &lVal, sizeof(lVal));
}
dam_addRowToTable(hstmt, hRow);
iRowCount++;
}
/* check if we have processed all result sets */
pProcDA->iCurResultSetNum++;
if (pProcDA->iCurResultSetNum < pProcDA->iTotalResultSets)
return DAM_SUCCESS_WITH_MORE_RESULT_SETS;
else {
DAM_HCOL hcolRetVal, hcolOutVal;
DAM_HROW hOutputRow;
hcolRetVal = dam_getCol(hstmt, "RETVAL");
hcolOutVal = dam_getCol(hstmt, "OUTVAL");
/* build output row */
hOutputRow = dam_allocOutputRow(hstmt);
lVal = pProcDA->iTotalResultSets;
iRetCode = dam_addValToRow(hstmt, hOutputRow, hcolRetVal, XO_TYPE_INTEGER,
&lVal, sizeof(lVal));
if (iRetCode != DAM_SUCCESS) return iRetCode;
lVal = pProcDA->iItems;
iRetCode = dam_addValToRow(hstmt, hOutputRow, hcolOutVal, XO_TYPE_INTEGER,
&lVal, sizeof(lVal));
if (iRetCode != DAM_SUCCESS) return iRetCode;
iRetCode = dam_addOutputRow(hstmt, hOutputRow);
if (iRetCode != DAM_SUCCESS) return iRetCode;
return DAM_SUCCESS;
}
}
else {
return DAM_FAILURE
return DAM_SUCCESS;
}
return DAM_SUCCESS;
}