Scalable Database Server, HiRDB Version 8 Command Reference
This section describes examples of data loading using UOCs.
These UOC examples are provided as sample databases. The storage directory is %PDDIR%\sample\sampleUOC.
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.
CREATE TABLE DIRECTORY (EMPLOYEE_NUMBER INTEGER,
BIRTH_DATE DATE,
HOMETOWN CHAR(10),
NAME CHAR(16));
10001, 68/04/30, BOSTON,DAVID IVERSON 10002, 64/09/13, TEXAS,DONALD YOUNG 20001, 70/11/02, CHICAGO,MATT CARR |
pdload DIRECTORY control-information-file-name |
source input-data-filename srcuoc library-name entry = date_change_func |
(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;
}
|
All Rights Reserved. Copyright (C) 2007, Hitachi, Ltd.