Genar Codina 0 Newbie Poster

I am trying to call a stored function (which makes basically a select query)from a VC++ program using OCI.
The description of the stored function is:

FUNCTION patrick.P_DICTIONARY_FOR_RISK_GROUP RETURNS REF CURSOR
Argument Name                  Type                    In/Out Default?
 ----------------  	     -------------                ---------------
 V_RISKGROUP              VARCHAR2                         IN
 V_DICTIONARY            VARCHAR2                         IN
 V_MARKETDATA           VARCHAR2                         IN
 V_MODE                     VARCHAR2                         IN
 V_DATE                      DATE                                IN

and with the returned value REF CURSOR, it could be possible to get all the rows returned from the function.

The problem is that, so far I could not get these rows. The function that I have written to get the rows is:

bool DBRiskOracleMgr::LoadRiskGroupScenarios(cGrid<cVariant>& pgrd_Output,const string& pstr_Proc,const string& pstr_Portfolio,
							            const string& pstr_Scenario,const string& pstr_MarketData,const string& pstr_Mode,
                                        DBRiskDate& dbRiskDate,const string& pstr_Currency,const bool pb_LogSQL)
{
        OCIError*           pOciError;
        char*                   pConnectChar    = "VERTEXD1";
        char*                   pUsernameChar   = "miau";
        char*                   pPasswordChar   = "miau";
        int                       answer;
        OCIStmt*           pOciStatement;
        char*                  sqlCharArray1 = "CALL VERTEX_RISK_ENGINE_CONFIG.CONFIG_CONTEXT_API.SET_CONTEXT('PC_OPTIONS_3D_UAT')";"BEGIN :success := patrick.P_DICTIONARY_FOR_RISK_GROUP('CHF_JPY_BASIS_OPTION','PRICE','COB',NULL,'14-Feb-2005'); END;";
        char*                  sqlCharArray2 = "BEGIN\n :result := P_DICTIONARY_FOR_RISK_GROUP('CHF_JPY_BASIS_OPTION','PRICE','COB',NULL,'14-Feb-2005');\nEND;";
        char                    szid[200];
        char                    ename[200];
        OCIEnv*            g_pOciEnvironment = NULL;
        OCIServer*        g_pOciServer = NULL;
        OCISession*       g_pOciSession = NULL;
        OCISvcCtx*       g_pOciServiceContext = NULL;
        sb2*                    pIndicator=0;
        sb2*                    pIndicator2=0;
        sb2*                    pIndicator3=0;
        OCIDefine*         pOciDefine;
        OCIDefine*         pOciDefine2;
        OCIBind*            pBind;
        OCIStmt*            cursor;
        string              slog;

        answer = OCIInitialize(OCI_THREADED, NULL, NULL, NULL, NULL);
        answer = OCIEnvInit(&g_pOciEnvironment, OCI_DEFAULT, 0, NULL);
        answer = OCIHandleAlloc(g_pOciEnvironment, (void **)&pOciError, OCI_HTYPE_ERROR, 0, NULL);
        answer = OCIHandleAlloc(g_pOciEnvironment, (void **)&g_pOciSession, OCI_HTYPE_SESSION, 0, NULL);
        answer = OCIHandleAlloc(g_pOciEnvironment, (void **)&g_pOciServer, OCI_HTYPE_SERVER, 0, NULL);
        answer = OCIHandleAlloc(g_pOciEnvironment, (void **)&g_pOciServiceContext, OCI_HTYPE_SVCCTX, 0, NULL);
        answer = OCIServerAttach(g_pOciServer, pOciError, (unsigned char *)pConnectChar, strlen(pConnectChar),
                                 OCI_DEFAULT);
        answer = OCIAttrSet(g_pOciSession, OCI_HTYPE_SESSION, (unsigned char *)pUsernameChar, strlen(pUsernameChar),
                            OCI_ATTR_USERNAME, pOciError);
        answer = OCIAttrSet(g_pOciSession, OCI_HTYPE_SESSION, (unsigned char *)pPasswordChar, strlen(pPasswordChar),
                            OCI_ATTR_PASSWORD, pOciError);
        answer = OCIAttrSet(g_pOciServiceContext, OCI_HTYPE_SVCCTX, g_pOciServer, 0, OCI_ATTR_SERVER, pOciError);
        answer = OCIAttrSet(g_pOciServiceContext, OCI_HTYPE_SVCCTX, g_pOciSession, 0, OCI_ATTR_SESSION, pOciError);
        answer = OCISessionBegin(g_pOciServiceContext, pOciError, g_pOciSession, OCI_CRED_RDBMS, OCI_DEFAULT);
        answer = OCIHandleAlloc(g_pOciEnvironment, (void **)(&pOciStatement),  OCI_HTYPE_STMT, 0, NULL);
        answer = OCIStmtPrepare(pOciStatement, pOciError, (unsigned char *)sqlCharArray1, strlen(sqlCharArray1),
                                OCI_NTV_SYNTAX, OCI_DEFAULT);
        answer = OCIStmtExecute(g_pOciServiceContext, pOciStatement, pOciError, 1, 0, NULL, NULL,
                                OCI_DEFAULT);
        writeToLog(sqlCharArray1);
        if (answer != 0)
        {
            writeToLog("Bad1");
            return false;
        }
        answer = OCIHandleAlloc(g_pOciEnvironment, (void **)(&cursor), OCI_HTYPE_STMT, 0, NULL);
        
        answer = OCIStmtPrepare(pOciStatement, pOciError, (unsigned char *)sqlCharArray2, strlen(sqlCharArray2),
                                OCI_NTV_SYNTAX, OCI_DEFAULT);
        answer = OCIBindByPos(pOciStatement,&pBind, pOciError, 1, &cursor, 0,SQLT_RSET,
                                  pIndicator2, 0,NULL, 0,0,OCI_DEFAULT);
 
        answer = OCIStmtExecute(g_pOciServiceContext, pOciStatement, pOciError, 1, 0, NULL, NULL,
                                OCI_DEFAULT);

        writeToLog(sqlCharArray2);
        if (answer != 0)
        {
            writeToLog("Bad2");
            return false;
        }
        answer = OCIDefineByPos(cursor,&pOciDefine, pOciError,2,szid,sizeof(szid),
                                SQLT_STR,pIndicator, 0, 0,OCI_DEFAULT);
        answer = OCIDefineByPos(cursor,&pOciDefine2, pOciError,1,ename,40,
                                SQLT_STR,pIndicator3, 0, 0,OCI_DEFAULT);
 
        while ((answer = OCIStmtFetch(cursor,pOciError, 1,OCI_FETCH_NEXT,OCI_DEFAULT)) == 0)
        {
                slog = string(szid) + string(ename);
                writeToLog(slog);
        }
        answer = OCIHandleFree(pOciError, OCI_HTYPE_ERROR);
    return true;
}

Any suggestion will be useful.
Thanks.