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.  /
  177. /**************************************************************************
  178. ***************************************************************************
  179. **                                                                       **
  180. **   Function Name : FtchCdcDealMktInfrmnDB                              **
  181. **                                                                       **
  182. **   Input Params  :                                                                                             **
  183. **                                                                       **
  184. **   Output Params :                                                     **
  185. **                                                                       **
  186. **   Description   :                                                     **
  187. **                                                                       **
  188. **   Return Value  : returns 0 on success and sqlcode on failure         **
  189. **                                                                       **
  190. **   Mod History   :                                                     **
  191. **                                                                       **
  192. ***************************************************************************
  193. **************************************************************************/
  194. RETURN_VALUE FtchCdcDealMktInfrmnDB(BOOL                  bStartOfScan,
  195.                                   CDC_DEAL_INQRY_IN_BODY  *pCDCDealInqryInBody,
  196.                                   CDC_DEAL_INQRY_OUT_BODY *pCDCDealInqryOutBody,
  197.                                   COUNT                   *pCount)
  198. {
  199.   #ifdef DBG 
  200.     ProcessEventLog(TRC_DBG,ERR_TRC,Info(0),"Entered FtchCdcDealMktInfrmnDB");
  201.   #endif 
  202.     EXEC SQL BEGIN DECLARE SECTION              ;
  203.     struct  sqlca   sqlca                       ;
  204.     QUERY_STRING    caQueryString[MAX_QUERY_LEN];
  205.   QUERY_STRING    caCnclString[MAX_QUERY_LEN] ;
  206.   COUNT           iDepth  =  CDC_DEAL_RECORDS ;
  207.   DESC            caTempStr[30]               ;
  208.   EXEC SQL END DECLARE SECTION                ;
  209.   memset(caQueryString,NULL,QUERY_STRING_LNGTH);
  210.   strcpy(caQueryString," SELECT ");
  211.   strcat(caQueryString," CDD_MKT_SRNO ,");
  212.   strcat(caQueryString," CDD_DEAL_DATE ,");
  213.   strcat(caQueryString," CDD_DEAL_IDNTY,");
  214.   strcat(caQueryString," CDD_STATUS_INDC,");
  215.   strcat(caQueryString," CDD_PRE_DEAL_VLDTE_INDC,");
  216.   strcat(caQueryString," CDD_DATA_CNTR_TRNSFR_INDC ");
  217.   strcat(caQueryString," FROM TRDX_CDC_DEAL_DTLS");
  218.   memset(caCnclString,NULL,sizeof(QUERY_STRING_LNGTH));
  219.   sprintf(caCnclString," WHERE CDD_MKT_SRNO = '%ld' AND CDD_DEAL_DATE >= to_date('%s','yyyymmdd') AND CDD_DEAL_DATE <= to_date('%s','yyyymmdd') ",
  220.     pCDCDealInqryInBody->lMktSrno,
  221.     pCDCDealInqryInBody->caFromDate,
  222.     pCDCDealInqryInBody->caToDate);
  223.   strcat(caQueryString,caCnclString);
  224.   if(!strcmp(pCDCDealInqryInBody->caDealSrno,"NULL"))
  225.   {
  226.   }
  227.   else
  228.   {
  229.     memset(caTempStr,0,sizeof(caTempStr));
  230.     strcpy(caTempStr,"'%");
  231.     strcat(caTempStr,pCDCDealInqryInBody->caDealSrno);
  232.     strcat(caTempStr,"%'");
  233.     memset(caCnclString,0,sizeof(caCnclString));
  234.     sprintf(caCnclString," AND CDD_DEAL_IDNTY like %s ",caTempStr);
  235.     strcat(caQueryString,caCnclString);
  236.   }
  237.   if(pCDCDealInqryInBody->iStatus NOT_EQUAL 0) /**  0 is not set any value **/
  238.   {
  239.     memset(caCnclString,0,sizeof(caCnclString));
  240.     sprintf(caCnclString," AND CDD_STATUS_INDC = '%ld' ",pCDCDealInqryInBody->iStatus);
  241.     strcat(caQueryString,caCnclString);
  242.   }
  243.    #ifdef DBG 
  244.         ProcessEventLog(TRC_DBG,ERR_TRC,Info(0),"query_string : [%s]",caQueryString);
  245.     #endif 
  246.   if(bStartOfScan)
  247.     {
  248.     EXEC SQL PREPARE FtchCdcDealInfrmnQueryDB FROM : caQueryString ;
  249.     if(sqlca.sqlcode)
  250.     {
  251.       ProcessEventLog(TRC_DBG,ERR_TRC,Warn(0),"Error in Prepare Statement. sqlcode : [%d]",sqlca.sqlcode);
  252.       return(sqlca.sqlcode);
  253.     }
  254.     EXEC SQL DECLARE FTCH_CDC_DEAL_INFRMN_CURSOR CURSOR FOR FtchCdcDealInfrmnQueryDB ;
  255.     if( sqlca.sqlcode NOT_EQUAL NO_ERROR )
  256.     {
  257.       ProcessEventLog(TRC_WRN,ERR_DB,Warn(sqlca.sqlcode),
  258.       "Err in declaring cursor FTCH_CDC_DEAL_INFRMN_CURSOR ");
  259.       return sqlca.sqlcode ;
  260.     }
  261.     EXEC SQL OPEN FTCH_CDC_DEAL_INFRMN_CURSOR;
  262.         if(sqlca.sqlcode NOT_EQUAL NO_ERROR)
  263.         {
  264.             ProcessEventLog(TRC_DBG,ERR_DB,Warn(sqlca.sqlcode)," Error in opening cursor FTCH_CDC_DEAL_INFRMN_CURSOR");
  265.             return(sqlca.sqlcode);
  266.         }
  267.   }
  268.   EXEC SQL FOR :iDepth FETCH FTCH_CDC_DEAL_INFRMN_CURSOR
  269.     INTO  :pCDCDealInqryOutBody;
  270.   *pCount  =  sqlca.sqlerrd[2]   ;
  271.     if(sqlca.sqlcode && abs(sqlca.sqlcode) NOT_EQUAL RECORD_NOT_FOUND)
  272.     {
  273.     ProcessEventLog(TRC_DBG,ERR_DB,Warn(sqlca.sqlcode),"%s"
  274.     ,"Error in fetching cursor FTCH_CDC_DEAL_INFRMN_CURSOR.");
  275.     return(sqlca.sqlcode);
  276.     }
  277.   #ifdef DBG 
  278.     ProcessEventLog(TRC_DBG,ERR_TRC,sqlca.sqlcode,"%s"," Exit FtchCdcDealMktInfrmnDB");
  279.   #endif 
  280.     return sqlca.sqlcode ;
  281. }
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值