概述
- /*
- * 循环取出数据,并且放回每次实际取出纪录的条数
- */
- /***************************************************************************
- ****************************************************************************
- ** FUNCTION NAME : PrcsCdcDealInqry **
- ** **
- ** INPUT PARAMS : CDC_DEAL_INQRY_IN *pCdcDealInqryIn **
- ** **
- ** OUTPUT PARAMS : **
- ** **
- ** DESCRIPTION : **
- ** **
- ** NON LOCAL DATA REF: **
- ** **
- ** CALLING FUNCTIONS : **
- ** **
- ** RETURN VALUE : iReturnValue **
- ** **
- ** MOD HISTORY : **
- ****************************************************************************
- ***************************************************************************/
- RETURN_VALUE PrcsCdcDealInqry(CDC_DEAL_INQRY_IN *pCdcDealInqryIn)
- {
- RETURN_VALUE iReturnValue = 0 ;
- BOOL bStatusValue = FALSE ;
- COUNT iNumOfRecord = 0 ;
- COUNT iCount = 0 ;
- CDC_DEAL_INQRY_IN_BODY sCdcDealInqryInBody ;
- CDC_DEAL_INQRY_IN_BODY *pCdcDealInqryInBody ;
- CDC_DEAL_INQRY_OUT_BODY saCDCDealInqryOutBody[CDC_DEAL_RECORDS];
- CDC_DEAL_INQRY_OUT sCdcDealInqryOut ;
- CDC_DEAL_INQRY_OUT *pCdcDealInqryOut ;
- pCdcDealInqryInBody = &sCdcDealInqryInBody ;
- pCdcDealInqryOut = &sCdcDealInqryOut ;
- memset(pCdcDealInqryInBody,NULL,sizeof(CDC_DEAL_INQRY_IN_BODY));
- memset(pCdcDealInqryOut,NULL,sizeof(CDC_DEAL_INQRY_OUT));
- pCdcDealInqryInBody = &pCdcDealInqryIn->sCDCDealInqryInBody ;
- #ifdef DBG
- ProcessEventLog(TRC_DBG,ERR_TRC,Info(iReturnValue),"%s","Entered function : PrcsCdcDealInqry");
- #endif
- #ifdef DBG
- ProcessEventLog(TRC_DBG,ERR_TRC,0,"Receive value Mktsrno is <%ld> ,caFromDate is <%s>, caToDate is <%s>, caDealSrno is <%s>, iStatus is <%ld> ",pCdcDealInqryInBody->lMktSrno, pCdcDealInqryInBody->caFromDate,pCdcDealInqryInBody->caToDate,pCdcDealInqryInBody->caDealSrno,pCdcDealInqryInBody->iStatus);
- #endif
- memset(saCDCDealInqryOutBody,NULL,
- sizeof(CDC_DEAL_INQRY_OUT_BODY)*CDC_DEAL_RECORDS);
- iReturnValue = FtchCdcDealMktInfrmnDB(YES,
- pCdcDealInqryInBody,
- saCDCDealInqryOutBody,
- &iNumOfRecord);
- if(abs(iReturnValue) EQUAL 0)
- {
- iNumOfRecord = CDC_DEAL_RECORDS ;
- }
- else if(abs(iReturnValue) EQUAL RECORD_NOT_FOUND&&iNumOfRecord NOT_EQUAL 0)
- {
- /*******************************************************************
- Some records had fetched,but not enough CDC_DEAL_RECORDS.NO ERROR
- ********************************************************************/
- bStatusValue = TRUE ;
- }
- else if(abs(iReturnValue) EQUAL RECORD_NOT_FOUND&&iNumOfRecord EQUAL 0)
- {
- ProcessEventLog(TRC_ERR,ERR_APPL,Warn(iReturnValue),"NO Record fetched for that asset.");
- return (iReturnValue);
- }
- else if(iReturnValue NOT_EQUAL 0 && abs(iReturnValue) NOT_EQUAL RECORD_NOT_FOUND)
- {
- ProcessEventLog(TRC_ERR,ERR_APPL,Warn(iReturnValue),"Error in function FtchCdcDealMktInfrmnDB from function PrcsCdcDealInqry");
- return (iReturnValue);
- }
- while(iReturnValue EQUAL 0
- ||
- (abs(iReturnValue) EQUAL RECORD_NOT_FOUND && iNumOfRecord NOT_EQUAL 0))
- {
- memset(pCdcDealInqryOut,NULL,sizeof(CDC_DEAL_INQRY_OUT));
- #ifdef DBG
- ProcessEventLog(TRC_DBG,ERR_TRC,0,"B4 Popu() Records Number Is ==> <%d> ",iNumOfRecord);
- #endif
- iReturnValue = PpltInfoForCdcDealInqry(iNumOfRecord,
- pCdcDealInqryIn,
- saCDCDealInqryOutBody,
- pCdcDealInqryOut);
- /*******(Begin) Only For Print ******
- for(int i=0; i<CDC_DEAL_RECORDS; i++)
- {
- #ifdef DBG
- ProcessEventLog(TRC_DBG,ERR_TRC,0,"Populate value(loop) DB value <%d> times ==> lMktSrno is <%ld> ,caDealDate is <%s>, caDealSrno is <%s>, iStatus is <%ld>, iPreDealVldteIndc is <%ld>, iDataCntrTrnsfrIndc is <%ld>",i+1,saCDCDealInqryOutBody[i].lMktSrno,saCDCDealInqryOutBody[i].caDealDate,saCDCDealInqryOutBody[i].caDealSrno,saCDCDealInqryOutBody[i].iStatus,saCDCDealInqryOutBody[i].iPreDealVldteIndc,saCDCDealInqryOutBody[i].iDataCntrTrnsfrIndc);
- #endif
- }
- *******(END) Only For Print ******/
- if(iReturnValue NOT_EQUAL 0)
- {
- ProcessEventLog(TRC_ERR,ERR_APPL,Warn(iReturnValue),"Error in function PpltInfoForCdcDealInqry from function PrcsCdcDealInqry");
- return (iReturnValue);
- }
- /*******************************************************************
- Return the total number of records which had fetched.
- ********************************************************************/
- pCdcDealInqryOut->sCDCDealInqryOutBodyDtls.iNumOfRecords = iNumOfRecord ;
- #ifdef DBG
- ProcessEventLog(TRC_DBG,ERR_TRC,0,"Total Number Of Records Fetched Is ==><%d> ",pCdcDealInqryOut->sCDCDealInqryOutBodyDtls.iNumOfRecords);
- #endif
- iReturnValue = SendToTrader(pCdcDealInqryOut,
- sizeof(CDC_DEAL_INQRY_OUT),
- TC_CDC_DEAL_OUT);
- if(iReturnValue NOT_EQUAL 0)
- {
- ProcessEventLog(TRC_ERR,ERR_APPL,Warn(iReturnValue),"Error in function : SendToTrader from function PrcsCdcDealInqry");
- return (iReturnValue);
- }
- iCount++ ;
- if(bStatusValue EQUAL TRUE)
- {
- break;
- }
- memset(saCDCDealInqryOutBody,NULL,
- sizeof(CDC_DEAL_INQRY_OUT_BODY)*CDC_DEAL_RECORDS);
- iReturnValue = FtchCdcDealMktInfrmnDB(NO,
- pCdcDealInqryInBody,
- saCDCDealInqryOutBody,
- &iNumOfRecord);
- if(abs(iReturnValue) EQUAL 0)
- {
- iNumOfRecord = CDC_DEAL_RECORDS ;
- }
- else if(abs(iReturnValue) EQUAL RECORD_NOT_FOUND&&iNumOfRecord NOT_EQUAL 0)
- {
- /*******************************************************************
- Some records had fetched,but not enough CDC_DEAL_RECORDS.NO ERROR
- ********************************************************************/
- bStatusValue = TRUE ;
- /*******************************************************************
- Get the exactly number of record .
- ********************************************************************/
- iNumOfRecord = iNumOfRecord - (iCount*CDC_DEAL_RECORDS) ;
- #ifdef DBG
- ProcessEventLog(TRC_DBG,ERR_TRC,0,"(Loop)Last Fetched Records Number Is ==><%d> ",iNumOfRecord);
- #endif
- }
- else if(abs(iReturnValue) EQUAL RECORD_NOT_FOUND&&iNumOfRecord EQUAL 0)
- {
- ProcessEventLog(TRC_ERR,ERR_APPL,Warn(iReturnValue),"NO Record fetched for that asset.");
- return (iReturnValue);
- }
- else if(iReturnValue NOT_EQUAL 0 && abs(iReturnValue) NOT_EQUAL RECORD_NOT_FOUND)
- {
- ProcessEventLog(TRC_ERR,ERR_APPL,Warn(iReturnValue),"Error in function FtchCdcDealMktInfrmnDB from function PrcsCdcDealInqry");
- return (iReturnValue);
- }
- } /* End loop of while */
- if(abs(iReturnValue) EQUAL RECORD_NOT_FOUND&&iNumOfRecord EQUAL 0)
- {
- memset(pCdcDealInqryOut,NULL,sizeof(CDC_DEAL_INQRY_OUT));
- memcpy(&pCdcDealInqryOut->sHeader,
- &pCdcDealInqryIn->sHeader,sizeof(HEADER));
- memcpy(&pCdcDealInqryOut->sTrailer,
- &pCdcDealInqryIn->sTrailer,sizeof(TRAILER));
- pCdcDealInqryOut->sHeader.error_code = RECORD_NOT_FOUND ;
- iReturnValue = SendToTrader(pCdcDealInqryOut,
- sizeof(CDC_DEAL_INQRY_OUT),
- TC_CDC_DEAL_OUT);
- if(iReturnValue NOT_EQUAL 0)
- {
- ProcessEventLog(TRC_ERR,ERR_APPL,Warn(iReturnValue),"Error in function : SendToTrader(1403) from function PrcsCdcDealInqry");
- return (iReturnValue);
- }
- }
- #ifdef DBG
- ProcessEventLog(TRC_DBG,ERR_TRC,Info(iReturnValue),"Exiting function: PrcsCdcDealInqry");
- #endif
- return (iReturnValue);
- }
- /*
- * DB函数
- /
- /**************************************************************************
- ***************************************************************************
- ** **
- ** Function Name : FtchCdcDealMktInfrmnDB **
- ** **
- ** Input Params : **
- ** **
- ** Output Params : **
- ** **
- ** Description : **
- ** **
- ** Return Value : returns 0 on success and sqlcode on failure **
- ** **
- ** Mod History : **
- ** **
- ***************************************************************************
- **************************************************************************/
- RETURN_VALUE FtchCdcDealMktInfrmnDB(BOOL bStartOfScan,
- CDC_DEAL_INQRY_IN_BODY *pCDCDealInqryInBody,
- CDC_DEAL_INQRY_OUT_BODY *pCDCDealInqryOutBody,
- COUNT *pCount)
- {
- #ifdef DBG
- ProcessEventLog(TRC_DBG,ERR_TRC,Info(0),"Entered FtchCdcDealMktInfrmnDB");
- #endif
- EXEC SQL BEGIN DECLARE SECTION ;
- struct sqlca sqlca ;
- QUERY_STRING caQueryString[MAX_QUERY_LEN];
- QUERY_STRING caCnclString[MAX_QUERY_LEN] ;
- COUNT iDepth = CDC_DEAL_RECORDS ;
- DESC caTempStr[30] ;
- EXEC SQL END DECLARE SECTION ;
- memset(caQueryString,NULL,QUERY_STRING_LNGTH);
- strcpy(caQueryString," SELECT ");
- strcat(caQueryString," CDD_MKT_SRNO ,");
- strcat(caQueryString," CDD_DEAL_DATE ,");
- strcat(caQueryString," CDD_DEAL_IDNTY,");
- strcat(caQueryString," CDD_STATUS_INDC,");
- strcat(caQueryString," CDD_PRE_DEAL_VLDTE_INDC,");
- strcat(caQueryString," CDD_DATA_CNTR_TRNSFR_INDC ");
- strcat(caQueryString," FROM TRDX_CDC_DEAL_DTLS");
- memset(caCnclString,NULL,sizeof(QUERY_STRING_LNGTH));
- sprintf(caCnclString," WHERE CDD_MKT_SRNO = '%ld' AND CDD_DEAL_DATE >= to_date('%s','yyyymmdd') AND CDD_DEAL_DATE <= to_date('%s','yyyymmdd') ",
- pCDCDealInqryInBody->lMktSrno,
- pCDCDealInqryInBody->caFromDate,
- pCDCDealInqryInBody->caToDate);
- strcat(caQueryString,caCnclString);
- if(!strcmp(pCDCDealInqryInBody->caDealSrno,"NULL"))
- {
- }
- else
- {
- memset(caTempStr,0,sizeof(caTempStr));
- strcpy(caTempStr,"'%");
- strcat(caTempStr,pCDCDealInqryInBody->caDealSrno);
- strcat(caTempStr,"%'");
- memset(caCnclString,0,sizeof(caCnclString));
- sprintf(caCnclString," AND CDD_DEAL_IDNTY like %s ",caTempStr);
- strcat(caQueryString,caCnclString);
- }
- if(pCDCDealInqryInBody->iStatus NOT_EQUAL 0) /** 0 is not set any value **/
- {
- memset(caCnclString,0,sizeof(caCnclString));
- sprintf(caCnclString," AND CDD_STATUS_INDC = '%ld' ",pCDCDealInqryInBody->iStatus);
- strcat(caQueryString,caCnclString);
- }
- #ifdef DBG
- ProcessEventLog(TRC_DBG,ERR_TRC,Info(0),"query_string : [%s]",caQueryString);
- #endif
- if(bStartOfScan)
- {
- EXEC SQL PREPARE FtchCdcDealInfrmnQueryDB FROM : caQueryString ;
- if(sqlca.sqlcode)
- {
- ProcessEventLog(TRC_DBG,ERR_TRC,Warn(0),"Error in Prepare Statement. sqlcode : [%d]",sqlca.sqlcode);
- return(sqlca.sqlcode);
- }
- EXEC SQL DECLARE FTCH_CDC_DEAL_INFRMN_CURSOR CURSOR FOR FtchCdcDealInfrmnQueryDB ;
- if( sqlca.sqlcode NOT_EQUAL NO_ERROR )
- {
- ProcessEventLog(TRC_WRN,ERR_DB,Warn(sqlca.sqlcode),
- "Err in declaring cursor FTCH_CDC_DEAL_INFRMN_CURSOR ");
- return sqlca.sqlcode ;
- }
- EXEC SQL OPEN FTCH_CDC_DEAL_INFRMN_CURSOR;
- if(sqlca.sqlcode NOT_EQUAL NO_ERROR)
- {
- ProcessEventLog(TRC_DBG,ERR_DB,Warn(sqlca.sqlcode)," Error in opening cursor FTCH_CDC_DEAL_INFRMN_CURSOR");
- return(sqlca.sqlcode);
- }
- }
- EXEC SQL FOR :iDepth FETCH FTCH_CDC_DEAL_INFRMN_CURSOR
- INTO :pCDCDealInqryOutBody;
- *pCount = sqlca.sqlerrd[2] ;
- if(sqlca.sqlcode && abs(sqlca.sqlcode) NOT_EQUAL RECORD_NOT_FOUND)
- {
- ProcessEventLog(TRC_DBG,ERR_DB,Warn(sqlca.sqlcode),"%s"
- ,"Error in fetching cursor FTCH_CDC_DEAL_INFRMN_CURSOR.");
- return(sqlca.sqlcode);
- }
- #ifdef DBG
- ProcessEventLog(TRC_DBG,ERR_TRC,sqlca.sqlcode,"%s"," Exit FtchCdcDealMktInfrmnDB");
- #endif
- return sqlca.sqlcode ;
- }
最后
以上就是爱笑白羊为你收集整理的C循环取出数据的全部内容,希望文章能够帮你解决C循环取出数据所遇到的程序开发问题。
如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。
本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
发表评论 取消回复