Example of Using a Variable-Length Array

This appendix describes an example of DBIO output using a variable-length array.

The following example retrieves data from an accessed database and saves the data to a variable-length array defined in ProMapper. Refer to this example when writing an application.

/**************************************
 * KIND     : Intermediary Module Function
 * NODE ID  : 1
 * NAME     : Variable-length output handling
 * DESCRIPTION :
 *************************************/
static long innerModule1(test_biz2Context *context)
{
    long rc = RC_NRM;

    // Variables Declaration
    long fetchCnt = 0; /*  */
    long fetchRc = 0; /*  */

    // Variables Initialization

    {
        /**************************************
         * KIND     : DBIO Fetch Loop
         * NODE ID  : 2
         * NAME     : testdev_meta_pf990 Fetch loop
         * DESCRIPTION :
         *************************************/
        testdev_meta_pf990In temporaryInput2;
        testdev_meta_pf990Out temporaryOutput2[10];

        bzero(&temporaryInput2, sizeof(testdev_meta_pf990In));
        bzero(temporaryOutput2, sizeof(testdev_meta_pf990Out) * 10);

        //DO_NOT_MODIFY_THIS_LINE-----------START_OF_CODE:DBIO_DYNAMIC_PARAMETER
           NODEID3----------------//
        //TODO Auto-generated method stub
        //DO_NOT_MODIFY_THIS_LINE-----------END_OF_CODE:DBIO_DYNAMIC_PARAMETER
          NODEID3------------------//


     PFM_TRYNJ(pfmDbioOpenCursorArray("testdev_meta_pf990",
                 &temporaryInput2, NULL, FMWDBIO_NOLOCK));
        //START_OF_CODE:testdev_meta_pf990 Fetch loop DBIO_FETCH_LOOP
        while (1)
        {
          {
                //DO_NOT_MODIFY_THIS_LINE-----------START_OF_CODE:BEFORE_CODE
                  NODEID3------------------//
                // TODO Auto-generated method stub
                //DO_NOT_MODIFY_THIS_LINE-----------END_OF_CODE:BEFORE_CODE
                  NODEID3--------------------//


                /**************************************
                 *   KIND              : DBIO_FETCH Callee Info
                 *   NAME              : testdev_meta_pf990
                 *   EXEC              : FETCH
                 *   INPUT             : testdev_meta_pf990In
                 *   OUTPUT            : testdev_meta_pf990Out
                 *   ARRAY INPUT       : NONE
                 *   ARRAY OUTPUT      : testdev_meta_pf990BundleOut
                 *   DYNAMIC STRUCTURE : NONE
                 *************************************/
               PFM_TRYNJ(pfmDbioFetchArray("testdev_meta_pf990", 10,
                                              &temporaryOutput2));
                 //DO_NOT_MODIFY_THIS_LINE-----------
                   START_OF_CODE:DBIO_FETCH_EXCEPTION NODEID3--------//

                 fetchRc = rc;

                 if (fetchRc != RC_NRM)
                 {
                 if (fetchRc == RC_NFD && pfmDbioGetRecordCount() == 0 )
                   {
                     PFM_ERR("TRSE001001", "There is no data matching the
                     condition. [%ld]", rc);
                     PFM_TRY(pfmDbioCloseCursorArray("testdev_meta_pf990"));
                     return fetchRc;
                   }
                   else if(fetchRc != RC_NFD ) {
                    PFM_ERR("TRSE001001", "[FAIL] Fetch Result rc=[%ld]
                             ErrCode[%ld], ErrorString[%s]", rc, pfmDbioGetErrorNo(),
                             pfmDbioGetErrorString());
                  PFM_TRY(pfmDbioCloseCursorArray("testdev_meta_pf990"));
                     return fetchRc;
                   }
                 }

               if(fetchRc==RC_NRM||(fetchRc==RC_NFD &&
                     pfmDbioGetRecordCount()%AS_TESTDEV_META_PF990>0 ))
                 {
                   PFM_DBG("Variable-length output handling");

                   /* Check whether the number of outputs exceeds max */
                   if( pfmVarrayCount(OUTPUT->test) >= 25 )
                   {
                     PFM_ERR("TRSE001001", "The max number of outputs is exceeded.
                              Allocated number:[%ld] ", pfmVarrayCount(OUTPUT->test));
                     return RC_ERR;
                   }

                   /* Variable-length array size */
                   if( rc==RC_NFD)
                   {
                     fetchCnt = pfmDbioGetRecordCount() % AS_TESTDEV_META_PF990;
                   }
                   else
                   {
                     fetchCnt = AS_TESTDEV_META_PF990;
                   }

                   /* Allocation to a variable-length array */
                   for( int i = 0; i < fetchCnt; i){
                   pfmVarrayAppend( OUTPUT->test, &temporaryOutput2[i]);
                     OUTPUT->cnt;
                   }
                 }

                 /* Break for last processing */
                 if(fetchRc == RC_NFD )
                 {
                   PFM_DBG("break for rc=[%ld]", rc);
                 break;
                 }
                 //DO_NOT_MODIFY_THIS_LINE-----------
                   END_OF_CODE:DBIO_FETCH_EXCEPTION NODEID3----------//

                 //DO_NOT_MODIFY_THIS_LINE-----------
                   START_OF_CODE:AFTER_CODE NODEID3------------------//
                 // TODO Auto-generated method stub
                 //DO_NOT_MODIFY_THIS_LINE-----------
                   END_OF_CODE:AFTER_CODE NODEID3--------------------//
          }
        }
        //END_OF_CODE:testdev_meta_pf990 Fetch loop DBIO_FETCH_LOOP

        PFM_TRY(pfmDbioCloseCursorArray("testdev_meta_pf990"));
        //DO_NOT_MODIFY_THIS_LINE-----------
          START_OF_CODE:DBIO_FETCH_LOOP_EXCEPTION NODEID2------------//
        // TODO Auto-generated method stub
        //DO_NOT_MODIFY_THIS_LINE-----------
        END_OF_CODE:DBIO_FETCH_LOOP_EXCEPTION NODEID2--------------//

    }
    return RC_NRM;

    FMW_CATCH:
       return rc;
}

The following describes the previous source.

① For DBIO created with multiple data of FETCH Exec type, open the cursor and repeatedly execute it to retrieve as much data as the array size.

② Multiple DBIO parameters are a map ID, the number of data to fetch at the same time, and an output structure.

③ If DBIO of FETCH Exec type returns the Not Found error, an exception must be handled according to whether the data actually does not exist or RC_NFD is returned because the FETCH array is not filled.

④ Error handling part. If a DBIO error occurs, the cursor is closed.

⑤ DBIO’s result value is used when it is RC_NRM or when it is RC_NFD for the last FETCH processing but the array is not filled.

⑥ fetch_cnt is the number of data fetched from an actual database. Therefore, if the output structure is variable length, data must be added to the structure by repeatedly using pfmVarrayAppend (fetch_cnt times). The number of data is processed through OUTPUT→cnt for the variable arguments of the output structure.

⑦ If an error is returned because the FETCH array is not filled, it is assumed that there is no more data and the while statement is exited.