17.10 - サンプルINMODルーチン - MultiLoad

Teradata® MultiLoadリファレンス

Product
MultiLoad
Release Number
17.10
Release Date
2021年6月
Content Type
プログラミング リファレンス
Publication ID
B035-2409-061K-JPN
Language
日本語 (日本)

Teradata MultiLoadソフトウェアで提供されているmlimod.cサンプルINMODルーチンのリストを以下に示します。

#include <stdio.h>
#include <stdlib.h>
/**********************************************************************/
/*                                                                    */
/* mlimod.c   - Sample Inmod for MultiLoad.                           */
/*                                                                    */
/* Purpose    - This inmod generates two integers per record.  The    */
/*              first is even and the second number is odd.           */
/*                                                                    */
/* Note       - The number of records per file is determined by the   */
/*              variable NUM_RECORDS                                  */
/*                                                                    */
/* Execute    - Build Inmod on a Unix system                          */
/*                compile and link into shared object                 */
/*                    cc -G mlimod.c - o mlimod.so                    */
/*                                                                    */
/*            - Build Inmod on a Win32 system                         */
/*                compile and link into dynamic link library          */
/*                    cl /DWIN32 /LD mlimod.c                         */
/*                                                                    */
/**********************************************************************/
static int msg_cnt = 0;
typedef struct {
int    ioseq;
short  len;
char   param[2000];
} param_type;
/* This structure is used to pass an odd and an even integer  */
/* back to multiload                                          */
typedef struct {
int   code;
int   len;
char   data[32768];
} data_type;
#ifdef WIN32                                          /* Change for WIN32 */
__declspec(dllexport) void _dynamn(data_type *data_buf , param_type *parm_buf)
#else
void _dynamn(data_buf, parm_buf)
data_type  *data_buf;
param_type *parm_buf;
#endif
{
	char *myptr;
	int  i;
	static int RECNUM = 0;       /* number of records to load */
	static int odd_counter = 0;  /* odd integer counter */
	static int even_counter = 0; /* even integer counter */
#ifdef DEBUG
	printf("\n");
	printf("jmod2: on input:\n");
	printf("jmod2:    message code:   %d\n", data_buf->code);
	printf("jmod2:      data bytes:   %d\n", data_buf->len);
	if (data_buf->len)
		printf("jmod2:            data:   *%s*\n", data_buf->data);
	printf("jmod2:     param ioseq:   %d\n", parm_buf->ioseq);
	printf("jmod2:     param bytes:   %d\n", parm_buf->len);
	if (parm_buf->len)
		printf("jmod2:       param str:   %s\n", parm_buf->param);
	printf("jmod2:     message cnt:   %d\n", ++msg_cnt);
#endif
	switch (data_buf->code)
	{
	case 0: printf("jmod2: initializing and returning 1st record:\n");
		RECNUM = 6;
		printf("jmod2: Records requested = %ld\n", RECNUM);
		if ( RECNUM <= 0 ) {
			printf("jmod2: numbers of records is <= 0 [%ld]\n", RECNUM);
		}
		/* initialize the counters */
		odd_counter = 1;
		even_counter = 2;
		/* copy the counters to the data buffer */
		myptr = (char *) &odd_counter;
		for (i=0; i<4; ++i, ++myptr) {
			data_buf->data[i] = *myptr;
		}
		myptr = (char *) &even_counter;
		for (i=4; i<8; ++i, ++myptr) {
			data_buf->data[i] = *myptr;
		}
		/* go to next values and increment the counters */
		odd_counter += 2;
		even_counter +=2;
		--RECNUM;
		/* return  the results */
		data_buf->code = 0;
		data_buf->len  = 8;
		break;
	case 1:
#ifdef DEBUG
		printf("jmod2: returning a record:\n");
#endif
		if (RECNUM) {
			/* copy the counters to the data buffer */
			myptr = (char *) &odd_counter;
			for (i=0; i<4; ++i, ++myptr) {
				data_buf->data[i] = *myptr;
			}
			myptr = (char *) &even_counter;
			for (i=4; i<8; ++i, ++myptr) {
				data_buf->data[i] = *myptr;
			}
			/* increment to next values and decrement record counter */
			odd_counter  += 2;
			even_counter += 2;
			--RECNUM;
			/* return  the results */
			data_buf->code = 0;
			data_buf->len  = 8;
			break;
		} else {
			/* done sending records, return non-zero result */
			printf("jmod2: all records sent\n");
			data_buf->code = 1;
			break;
		}
	 case 2: printf("jmod2: repositioning to last checkpoint (HOST)\n");
		 data_buf->code = 0;
		 data_buf->len  = 0;
		 break;
	 case 3: printf("jmod2: taking a checkpoint\n");
		 data_buf->code = 0;
		 data_buf->len  = 0;
		 break;
	 case 4: printf("jmod2: repositioning to last checkpoint (DBC)\n");
		 data_buf->code = 0;
		 data_buf->len  = 0;
		 break;
	 case 5: printf("jmod2: terminating:\n");
		 data_buf->code = 0;
		 data_buf->len  = 0;
		 break;
	 case 6: printf("jmod2: initializing and receiving 1st record:\n");
		 data_buf->data[1] = '%';
		 data_buf->code = 0;
		 break;
	 case 7: printf("jmod2: receiving a record:\n");
		 data_buf->data[1] = '%';
		 data_buf->code = 0;
		 break;
      }
#ifdef DEBUG
	printf("jmod2: on output:\n");
	printf("jmod2:    message code:   %d\n", data_buf->code);
	printf("jmod2:      data bytes:   %d\n", data_buf->len);
	if (data_buf->len)
		printf("jmod2:            data:   *%s*\n", data_buf->data);
	printf("\n");
#endif
}