C循环取出数据

  1. /*
  2.  * 循环取出数据,并且放回每次实际取出纪录的条数
  3.  */
  4. /***************************************************************************
  5. ****************************************************************************
  6. **   FUNCTION NAME     :  PrcsCdcDealInqry                                **
  7. **                                                                        **
  8. **   INPUT PARAMS      :  CDC_DEAL_INQRY_IN   *pCdcDealInqryIn            **
  9. **                                                                                                            **
  10. **   OUTPUT PARAMS     :                                                  **
  11. **                                                                        **
  12. **   DESCRIPTION       :                                                  **
  13. **                                                                        **
  14. **   NON LOCAL DATA REF:                                                  **
  15. **                                                                        **
  16. **   CALLING FUNCTIONS :                                                          **
  17. **                                                                        **
  18. **   RETURN VALUE      :  iReturnValue                                    **
  19. **                                                                                                            **
  20. **   MOD HISTORY       :                                                                          **
  21. ****************************************************************************
  22. ***************************************************************************/
  23. RETURN_VALUE PrcsCdcDealInqry(CDC_DEAL_INQRY_IN   *pCdcDealInqryIn)
  24. {
  25.   RETURN_VALUE              iReturnValue    = 0     ;
  26.   BOOL                      bStatusValue    = FALSE ;
  27.   COUNT                     iNumOfRecord    = 0     ;
  28.   COUNT                     iCount          = 0     ;
  29.   CDC_DEAL_INQRY_IN_BODY    sCdcDealInqryInBody     ;
  30.   CDC_DEAL_INQRY_IN_BODY    *pCdcDealInqryInBody    ;
  31.   CDC_DEAL_INQRY_OUT_BODY   saCDCDealInqryOutBody[CDC_DEAL_RECORDS];
  32.   CDC_DEAL_INQRY_OUT        sCdcDealInqryOut        ;
  33.   CDC_DEAL_INQRY_OUT        *pCdcDealInqryOut       ;
  34.   pCdcDealInqryInBody   =   &sCdcDealInqryInBody    ;
  35.   pCdcDealInqryOut      =   &sCdcDealInqryOut       ;
  36.   memset(pCdcDealInqryInBody,NULL,sizeof(CDC_DEAL_INQRY_IN_BODY));
  37.   memset(pCdcDealInqryOut,NULL,sizeof(CDC_DEAL_INQRY_OUT));
  38.   pCdcDealInqryInBody = &pCdcDealInqryIn->sCDCDealInqryInBody ;
  39.   #ifdef DBG
  40.     ProcessEventLog(TRC_DBG,ERR_TRC,Info(iReturnValue),"%s","Entered function : PrcsCdcDealInqry");
  41.   #endif
  42.   #ifdef DBG
  43.     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);
  44.   #endif
  45.   memset(saCDCDealInqryOutBody,NULL,
  46.     sizeof(CDC_DEAL_INQRY_OUT_BODY)*CDC_DEAL_RECORDS);
  47.   iReturnValue = FtchCdcDealMktInfrmnDB(YES,
  48.                                         pCdcDealInqryInBody,
  49.                                         saCDCDealInqryOutBody,
  50.                                         &iNumOfRecord);
  51.   if(abs(iReturnValue)  EQUAL 0)
  52.   {
  53.     iNumOfRecord  = CDC_DEAL_RECORDS ;
  54.   }
  55.   else if(abs(iReturnValue) EQUAL RECORD_NOT_FOUND&&iNumOfRecord NOT_EQUAL 0)
  56.   {
  57.     /*******************************************************************
  58.       Some records had fetched,but not enough CDC_DEAL_RECORDS.NO ERROR
  59.     ********************************************************************/
  60.     bStatusValue  = TRUE ;
  61.   }
  62.   else if(abs(iReturnValue) EQUAL RECORD_NOT_FOUND&&iNumOfRecord EQUAL 0)
  63.   {
  64.     ProcessEventLog(TRC_ERR,ERR_APPL,Warn(iReturnValue),"NO Record fetched for that asset.");
  65.     return (iReturnValue);
  66.   }
  67.   else if(iReturnValue NOT_EQUAL 0 && abs(iReturnValue) NOT_EQUAL RECORD_NOT_FOUND)
  68.   {
  69.     ProcessEventLog(TRC_ERR,ERR_APPL,Warn(iReturnValue),"Error in function FtchCdcDealMktInfrmnDB from function PrcsCdcDealInqry");
  70.     return (iReturnValue);
  71.   }
  72.   while(iReturnValue EQUAL 0
  73.                   ||
  74.     (abs(iReturnValue) EQUAL RECORD_NOT_FOUND  && iNumOfRecord NOT_EQUAL 0))
  75.     {
  76.     memset(pCdcDealInqryOut,NULL,sizeof(CDC_DEAL_INQRY_OUT));
  77.   #ifdef DBG
  78.       ProcessEventLog(TRC_DBG,ERR_TRC,0,"B4 Popu() Records Number Is ==> <%d> ",iNumOfRecord);
  79.   #endif
  80.     iReturnValue =  PpltInfoForCdcDealInqry(iNumOfRecord,
  81.                                             pCdcDealInqryIn,
  82.                                             saCDCDealInqryOutBody,
  83.                                             pCdcDealInqryOut);
  84.     /*******(Begin)  Only For Print  ******
  85.     for(int i=0;  i<CDC_DEAL_RECORDS; i++)
  86.     {
  87.       #ifdef DBG
  88.       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);
  89.       #endif
  90.     }
  91.     *******(END)  Only For Print  ******/
  92.     if(iReturnValue NOT_EQUAL 0)
  93.     {
  94.       ProcessEventLog(TRC_ERR,ERR_APPL,Warn(iReturnValue),"Error in function PpltInfoForCdcDealInqry from function PrcsCdcDealInqry");
  95.       return (iReturnValue);
  96.     }
  97.     /*******************************************************************
  98.       Return the total number of records which had fetched.
  99.     ********************************************************************/
  100.     pCdcDealInqryOut->sCDCDealInqryOutBodyDtls.iNumOfRecords  =  iNumOfRecord  ;
  101.     #ifdef DBG
  102.       ProcessEventLog(TRC_DBG,ERR_TRC,0,"Total Number Of Records Fetched Is ==><%d> ",pCdcDealInqryOut->sCDCDealInqryOutBodyDtls.iNumOfRecords);
  103.     #endif
  104.     iReturnValue  = SendToTrader(pCdcDealInqryOut,
  105.                                   sizeof(CDC_DEAL_INQRY_OUT),
  106.                                   TC_CDC_DEAL_OUT);
  107.     if(iReturnValue NOT_EQUAL 0)
  108.     {
  109.       ProcessEventLog(TRC_ERR,ERR_APPL,Warn(iReturnValue),"Error in function : SendToTrader from function PrcsCdcDealInqry");
  110.       return (iReturnValue);
  111.     }
  112.     iCount++  ;
  113.     if(bStatusValue EQUAL TRUE)
  114.     {
  115.       break;
  116.     }
  117.     memset(saCDCDealInqryOutBody,NULL,
  118.     sizeof(CDC_DEAL_INQRY_OUT_BODY)*CDC_DEAL_RECORDS);
  119.     iReturnValue = FtchCdcDealMktInfrmnDB(NO,
  120.                                           pCdcDealInqryInBody,
  121.                                           saCDCDealInqryOutBody,
  122.                                           &iNumOfRecord);
  123.     if(abs(iReturnValue)  EQUAL 0)
  124.     {
  125.       iNumOfRecord  = CDC_DEAL_RECORDS ;
  126.     }
  127.     else if(abs(iReturnValue) EQUAL RECORD_NOT_FOUND&&iNumOfRecord NOT_EQUAL 0)
  128.     {
  129.       /*******************************************************************
  130.         Some records had fetched,but not enough CDC_DEAL_RECORDS.NO ERROR
  131.       ********************************************************************/
  132.        bStatusValue  = TRUE ;
  133.       /*******************************************************************
  134.         Get the exactly number of record .
  135.       ********************************************************************/
  136.       iNumOfRecord  = iNumOfRecord - (iCount*CDC_DEAL_RECORDS)  ;
  137.       #ifdef DBG
  138.         ProcessEventLog(TRC_DBG,ERR_TRC,0,"(Loop)Last Fetched Records Number Is ==><%d> ",iNumOfRecord);
  139.       #endif
  140.     }
  141.     else if(abs(iReturnValue) EQUAL RECORD_NOT_FOUND&&iNumOfRecord EQUAL 0)
  142.     {
  143.       ProcessEventLog(TRC_ERR,ERR_APPL,Warn(iReturnValue),"NO Record fetched for that asset.");
  144.       return (iReturnValue);
  145.     }
  146.     else if(iReturnValue NOT_EQUAL 0 && abs(iReturnValue) NOT_EQUAL RECORD_NOT_FOUND)
  147.     {
  148.       ProcessEventLog(TRC_ERR,ERR_APPL,Warn(iReturnValue),"Error in function FtchCdcDealMktInfrmnDB from function PrcsCdcDealInqry");
  149.       return (iReturnValue);
  150.     }
  151.   } /*  End loop of while */
  152.   if(abs(iReturnValue) EQUAL RECORD_NOT_FOUND&&iNumOfRecord EQUAL 0)
  153.   {
  154.     memset(pCdcDealInqryOut,NULL,sizeof(CDC_DEAL_INQRY_OUT));
  155.     memcpy(&pCdcDealInqryOut->sHeader,
  156.          &pCdcDealInqryIn->sHeader,sizeof(HEADER));
  157.     memcpy(&pCdcDealInqryOut->sTrailer,
  158.          &pCdcDealInqryIn->sTrailer,sizeof(TRAILER));
  159.     pCdcDealInqryOut->sHeader.error_code = RECORD_NOT_FOUND ;
  160.     iReturnValue  = SendToTrader(pCdcDealInqryOut,
  161.                                   sizeof(CDC_DEAL_INQRY_OUT),
  162.                                   TC_CDC_DEAL_OUT);
  163.     if(iReturnValue NOT_EQUAL 0)
  164.     {
  165.       ProcessEventLog(TRC_ERR,ERR_APPL,Warn(iReturnValue),"Error in function : SendToTrader(1403) from function PrcsCdcDealInqry");
  166.       return (iReturnValue);
  167.     }
  168.   }
  169.   #ifdef DBG
  170.     ProcessEventLog(TRC_DBG,ERR_TRC,Info(iReturnValue),"Exiting function: PrcsCdcDealInqry");
  171.   #endif
  172.   return (iReturnValue);
  173. }
  174. /*
  175.  *  DB函数
  176.  /
  1. /**************************************************************************
  2. ***************************************************************************
  3. **                                                                       **
  4. **   Function Name : FtchCdcDealMktInfrmnDB                              **
  5. **                                                                       **
  6. **   Input Params  :                                                                                             **
  7. **                                                                       **
  8. **   Output Params :                                                     **
  9. **                                                                       **
  10. **   Description   :                                                     **
  11. **                                                                       **
  12. **   Return Value  : returns 0 on success and sqlcode on failure         **
  13. **                                                                       **
  14. **   Mod History   :                                                     **
  15. **                                                                       **
  16. ***************************************************************************
  17. **************************************************************************/
  18. RETURN_VALUE FtchCdcDealMktInfrmnDB(BOOL                  bStartOfScan,
  19.                                   CDC_DEAL_INQRY_IN_BODY  *pCDCDealInqryInBody,
  20.                                   CDC_DEAL_INQRY_OUT_BODY *pCDCDealInqryOutBody,
  21.                                   COUNT                   *pCount)
  22. {
  23.   #ifdef DBG
  24.     ProcessEventLog(TRC_DBG,ERR_TRC,Info(0),"Entered FtchCdcDealMktInfrmnDB");
  25.   #endif
  26.     EXEC SQL BEGIN DECLARE SECTION              ;
  27.     struct  sqlca   sqlca                       ;
  28.     QUERY_STRING    caQueryString[MAX_QUERY_LEN];
  29.   QUERY_STRING    caCnclString[MAX_QUERY_LEN] ;
  30.   COUNT           iDepth  =  CDC_DEAL_RECORDS ;
  31.   DESC            caTempStr[30]               ;
  32.   EXEC SQL END DECLARE SECTION                ;
  33.   memset(caQueryString,NULL,QUERY_STRING_LNGTH);
  34.   strcpy(caQueryString," SELECT ");
  35.   strcat(caQueryString," CDD_MKT_SRNO ,");
  36.   strcat(caQueryString," CDD_DEAL_DATE ,");
  37.   strcat(caQueryString," CDD_DEAL_IDNTY,");
  38.   strcat(caQueryString," CDD_STATUS_INDC,");
  39.   strcat(caQueryString," CDD_PRE_DEAL_VLDTE_INDC,");
  40.   strcat(caQueryString," CDD_DATA_CNTR_TRNSFR_INDC ");
  41.   strcat(caQueryString," FROM TRDX_CDC_DEAL_DTLS");
  42.   memset(caCnclString,NULL,sizeof(QUERY_STRING_LNGTH));
  43.   sprintf(caCnclString," WHERE CDD_MKT_SRNO = '%ld' AND CDD_DEAL_DATE >= to_date('%s','yyyymmdd') AND CDD_DEAL_DATE <= to_date('%s','yyyymmdd') ",
  44.     pCDCDealInqryInBody->lMktSrno,
  45.     pCDCDealInqryInBody->caFromDate,
  46.     pCDCDealInqryInBody->caToDate);
  47.   strcat(caQueryString,caCnclString);
  48.   if(!strcmp(pCDCDealInqryInBody->caDealSrno,"NULL"))
  49.   {
  50.   }
  51.   else
  52.   {
  53.     memset(caTempStr,0,sizeof(caTempStr));
  54.     strcpy(caTempStr,"'%");
  55.     strcat(caTempStr,pCDCDealInqryInBody->caDealSrno);
  56.     strcat(caTempStr,"%'");
  57.     memset(caCnclString,0,sizeof(caCnclString));
  58.     sprintf(caCnclString," AND CDD_DEAL_IDNTY like %s ",caTempStr);
  59.     strcat(caQueryString,caCnclString);
  60.   }
  61.   if(pCDCDealInqryInBody->iStatus NOT_EQUAL 0) /**  0 is not set any value **/
  62.   {
  63.     memset(caCnclString,0,sizeof(caCnclString));
  64.     sprintf(caCnclString," AND CDD_STATUS_INDC = '%ld' ",pCDCDealInqryInBody->iStatus);
  65.     strcat(caQueryString,caCnclString);
  66.   }
  67.    #ifdef DBG
  68.         ProcessEventLog(TRC_DBG,ERR_TRC,Info(0),"query_string : [%s]",caQueryString);
  69.     #endif
  70.   if(bStartOfScan)
  71.     {
  72.     EXEC SQL PREPARE FtchCdcDealInfrmnQueryDB FROM : caQueryString ;
  73.     if(sqlca.sqlcode)
  74.     {
  75.       ProcessEventLog(TRC_DBG,ERR_TRC,Warn(0),"Error in Prepare Statement. sqlcode : [%d]",sqlca.sqlcode);
  76.       return(sqlca.sqlcode);
  77.     }
  78.     EXEC SQL DECLARE FTCH_CDC_DEAL_INFRMN_CURSOR CURSOR FOR FtchCdcDealInfrmnQueryDB ;
  79.     if( sqlca.sqlcode NOT_EQUAL NO_ERROR )
  80.     {
  81.       ProcessEventLog(TRC_WRN,ERR_DB,Warn(sqlca.sqlcode),
  82.       "Err in declaring cursor FTCH_CDC_DEAL_INFRMN_CURSOR ");
  83.       return sqlca.sqlcode ;
  84.     }
  85.     EXEC SQL OPEN FTCH_CDC_DEAL_INFRMN_CURSOR;
  86.         if(sqlca.sqlcode NOT_EQUAL NO_ERROR)
  87.         {
  88.             ProcessEventLog(TRC_DBG,ERR_DB,Warn(sqlca.sqlcode)," Error in opening cursor FTCH_CDC_DEAL_INFRMN_CURSOR");
  89.             return(sqlca.sqlcode);
  90.         }
  91.   }
  92.   EXEC SQL FOR :iDepth FETCH FTCH_CDC_DEAL_INFRMN_CURSOR
  93.     INTO  :pCDCDealInqryOutBody;
  94.   *pCount  =  sqlca.sqlerrd[2]   ;
  95.     if(sqlca.sqlcode && abs(sqlca.sqlcode) NOT_EQUAL RECORD_NOT_FOUND)
  96.     {
  97.     ProcessEventLog(TRC_DBG,ERR_DB,Warn(sqlca.sqlcode),"%s"
  98.     ,"Error in fetching cursor FTCH_CDC_DEAL_INFRMN_CURSOR.");
  99.     return(sqlca.sqlcode);
  100.     }
  101.   #ifdef DBG
  102.     ProcessEventLog(TRC_DBG,ERR_TRC,sqlca.sqlcode,"%s"," Exit FtchCdcDealMktInfrmnDB");
  103.   #endif
  104.     return sqlca.sqlcode ;
  105. }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值