5.10.3 Examples of UOCs

This section describes examples of data loading using UOCs.

These UOC examples are provided as sample databases. The storage directory is %PDDIR%\sample\sampleUOC.

Organization of this subsection
(1) Example of data loading using UOC

(1) Example of data loading using UOC

This example changes an input data file with a 2-digit year designation to a 4-digit designation to store the data in a Y2K-supported database that can handle dates in the year 2000 and beyond. The input data file is in DAT format, and pdload is used to input the input data file.

(a) Database table definition

CREATE TABLE DIRECTORY (EMPLOYEE_NUMBER INTEGER,
                     BIRTH_DATE DATE,
                     HOMETOWN CHAR(10),
                     NAME CHAR(16));

(b) Format of input data file

10001, 68/04/30, BOSTON,DAVID IVERSON
10002, 64/09/13, TEXAS,DONALD YOUNG
20001, 70/11/02, CHICAGO,MATT CARR

(c) Command format

pdload DIRECTORY control-information-file-name

(d) Control information file

source input-data-filename
srcuoc library-name entry = date_change_func

(e) UOC example
(File name: sample1.c)

/*****************************************************************************
**                                                                          **
**  HiRDB sample Data input User Own Coding (for CSV file)                  **
**                          ~    ~   ~                                      **
**  name    :   date_change_func                                            **
**                                                                          **
**  func    :   YY/MM/DD  ===>  YYYY-MM-DD                                  **
**                                                                          **
**  i/o     :   none                                                        **
**                                                                          **
**  return  :   none                                                        **
**                                                                          **
*****************************************************************************/
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <errno.h>
#include <pdutluoc.h>                                                             1

#define DATELEN         10                  /* DATE length                  */

   static  void    sub_date_change(char *,char *);

void date_change_func(
   UTL_UOC_INF    *uocinf                  /* A(UOC interface area)        */    2
){
   long            wk_leng;                /* length                       */
   char            date_data[10];          /* DATE (HiRDB)                 */
   char           *date_ptr;               /* A(birth date)                */
   char           *address_p;              /* A(native)                    */
   static  char    buff[512];              /* buffer                       */

   switch(uocinf->req_cd){                                                       3
   case UTL_UOC_START:
/*--------------------------------------------------------------------------*/
/*  START                                                                   */
/*--------------------------------------------------------------------------*/
       uocinf->edit_adr = buff;
       uocinf->rtn_code = UTL_UOC_NML;
       break;
   case UTL_UOC_EDIT:
/*--------------------------------------------------------------------------*/
/*  EDIT                                                                    */
/*--------------------------------------------------------------------------*/
       date_ptr = strchr(uocinf->data_adr,',');
       if (date_ptr == NULL){
           strcpy(uocinf->err_msg,"Invalid data");
           goto OWARI;
       }
       sub_date_change(++date_ptr,date_data);
       wk_leng = (long)date_ptr - (long)uocinf->data_adr;
       strncpy(buff,uocinf->data_adr,wk_leng);
       strncpy((char*)((long)buff + wk_leng),date_data,DATELEN);
       wk_leng += DATELEN;
       address_p = strchr(date_ptr,',');
       strcpy((char*)((long)buff + wk_leng),address_p);
       uocinf->rtn_code = UTL_UOC_NML;
       break;
   case UTL_UOC_END:
   case UTL_UOC_TERM:
/*--------------------------------------------------------------------------*/
/*  END                                                                     */
/*--------------------------------------------------------------------------*/
       uocinf->rtn_code = UTL_UOC_NML;
       break;
   default:
       strcpy(uocinf->err_msg,"Invalid request code");
       goto OWARI;
   }
   return;
OWARI:
   uocinf->rtn_code = UTL_UOC_ERR;
   return;
}

static void sub_date_change(
   char    *year_two,                      /* YY/MM/DD                     */
   char    *year_four                      /* YYYY-MM-DD                   */
){
   strcpy(year_four,"19");
   strncat(year_four,year_two,8);
   year_four[4] = '-';
   year_four[7] = '-';
   return;
}

Explanation
  1. Acquire the UOC creation header provided by HiRDB.
  2. Receive the address of the UOC interface area as an argument.
  3. Determine the call type and execute the appropriate processing.