Nonstop Database, HiRDB Version 9 UAP Development Guide
This section uses a sample UAP that executes data loading (database load utility). The following figure shows a sample server-client configuration for a HiRDB/Single Server.
Figure 12-2 Sample server-client configuration for a HiRDB/Single Server
To execute a data-loading UAP with the server-client configuration shown in Figure 12-2, you need to define the following information beforehand:
PDASTUSER=USERA/USERA PDUSER=USERB/USERB
You can now execute the data-loading UAP. For details about each client environment definition, see 6.6.4 Environment definition information.
The following shows a sample UAP for loading data:
#include <stdio.h> #include <string.h> #include <stdlib.h> EXEC SQL BEGIN DECLARE SECTION; char CmdLine[30000]; /* CmdLine variable */ long ReturnCode; /* variable receiving return code */ long OutBufLen; /* size of area for receiving execution result */ long CmdRetCode; /* variable for receiving executed command's return code */ long OutDataLen; /* variable for receiving the length of execution result */ PDOUTBUF OutBuf; /* area for receiving execution result */ char EnvGroup[256]; /* environment variable group name variable */ EXEC SQL END DECLARE SECTION; void main() { strcpy(CmdLine,"pdhold -r RDDATA10"); /* specifying execution command line command line (RDAREA shutdown) */ OutBuf = malloc(30000); /* allocating the execution result receiving area */ if (OutBuf == NULL){ /* memory allocation error */ printf("Memory allocation error\n"); return ; } OutBufLen = 30000 ; /* specifying the size of execution result receiving area */ EnvGroup[0] = '\0' ; /* specifying no environment variable group */ /* Command execution */ EXEC SQL COMMAND EXECUTE :CmdLine, :ReturnCode, :OutBufLen, :OutDataLen, :OutBuf, :CmdRetCode, :EnvGroup ; if (ReturnCode == p_rdb_RC_NORM) { /* if COMMAND EXECUTE terminates normally */ if (CmdRetCode==0) { /* if command execution is normal */ /* Specifying execution command line (to execute dataloading) */ strcpy(CmdLine,"pdload -i c -be STOCK c:\HiRDB_S\conf\LOAD"); EXEC SQL COMMAND EXECUTE :CmdLine, :ReturnCode, :OutBufLen, :OutDataLen, :OutBuf, :CmdRetCode, :EnvGroup ; if (ReturnCode == p_rdb_RC_NORM) { /* if COMMAND EXECUTE terminates normally */ if (CmdRetCode==0) { /* if command execution is normal */ printf("pdload command successfully\n"); printf("%s\n", OutBuf); } else { /* execution command error */ printf("pdload command Error,Code = %d\n", CmdRetCode); printf("%s\n", OutBuf); } } else { /* COMMAND EXECUTE error */ printf("COMMAND EXECUTE Error,Code = %d\n", ReturnCode); printf("%s\n", OutBuf); } } else { /* execution command error */ printf("pdhold command Error,Code = %d\n", CmdRetCode); printf("%s\n", OutBuf); } strcpy(CmdLine,"pdrels -r RDDATA10"); /* specifying execution command line (RDAREA shutdown release) */ EXEC SQL COMMAND EXECUTE :CmdLine, :ReturnCode, :OutBufLen, :OutDataLen, :OutBuf, :CmdRetCode, :EnvGroup ; if (ReturnCode == p_rdb_RC_NORM) { /* if COMMAND EXECUTE terminates normally */ if (CmdRetCode!=0) { /* execution command error */ printf("pdrels command Error,Code = %d\n", CmdRetCode); printf("%s\n", OutBuf); } } else { /* COMMAND EXECUTE error */ printf("COMMAND EXECUTE Error,Code = %d\n", ReturnCode); printf("%s\n", OutBuf); } } else { /* COMMAND EXECUTE error */ printf("COMMAND EXECUTE Error,Code = %d\n", ReturnCode); printf("%s\n", OutBuf); } return ; }
This section uses a sample UAP that executes data loading (database load utility). The following figure shows a sample server-client configuration for a HiRDB/Parallel Server.
Figure 12-3 Sample server-client configuration for a HiRDB/Parallel Server
To execute a data-loading UAP with the server-client configuration shown in Figure 12-3, you need to define the following information beforehand:
PDASTUSER=USERA/USERA PDUSER=USERB/USERB
You can now execute the data-loading UAP. For details about each client environment definition, see 6.6.4 Environment definition information.
The following shows a sample UAP for loading data:
#include <stdio.h> #include <string.h> #include <stdlib.h> EXEC SQL BEGIN DECLARE SECTION; char CmdLine[30000]; /* CmdLine variable */ long ReturnCode; /* variable receiving return code */ long OutBufLen; /* size of area for receiving execution result */ long CmdRetCode; /* variable for receiving executed command's return code */ long OutDataLen; /* variable for receiving the length of execution result */ PDOUTBUF OutBuf; /* area for receiving execution result */ char EnvGroup[256]; /* environment variable group name variable */ EXEC SQL END DECLARE SECTION; void main() { strcpy(CmdLine,"pdhold -r RDDATA10"); /* specifying execution command line (RDAREA shutdown) */ OutBuf = malloc(30000); /* allocating the execution result receiving area */ if (OutBuf == NULL){ /* memory allocation error */ printf("Memory allocation error\n"); return ; } OutBufLen = 30000 ; /* specifying the size of execution result receiving area */ EnvGroup[0] = '\0' ; /* specifying no environment variable group */ /* Command execution */ EXEC SQL COMMAND EXECUTE :CmdLine, :ReturnCode, :OutBufLen, :OutDataLen, :OutBuf, :CmdRetCode, :EnvGroup ; if (ReturnCode == p_rdb_RC_NORM) { /* if COMMAND EXECUTE terminates normally */ if (CmdRetCode==0) { /* if command execution is normal */ /* Specifying execution command line (to execute dataloading) */ strcpy(CmdLine,"pdload -i c -be STOCK c:\HiRDB_P\conf\LOAD"); EXEC SQL COMMAND EXECUTE :CmdLine, :ReturnCode, :OutBufLen, :OutDataLen, :OutBuf, :CmdRetCode, :EnvGroup ; if (ReturnCode == p_rdb_RC_NORM) { /* if COMMAND EXECUTE terminates normally */ if (CmdRetCode==0) { /* if command execution is normal */ printf("pdload command successfully\n"); printf("%s\n", OutBuf); } else { /* execution command error */ printf("pdload command Error,Code = %d\n", CmdRetCode); printf("%s\n", OutBuf); } } else { /* COMMAND EXECUTE error */ printf("COMMAND EXECUTE Error,Code = %d\n", ReturnCode); printf("%s\n", OutBuf); } } else { /* execution command error */ printf("pdhold command Error,Code = %d\n", CmdRetCode); printf("%s\n", OutBuf); } strcpy(CmdLine,"pdrels -r RDDATA10"); /* specifying execution command line (RDAREA shutdown release) */ EXEC SQL COMMAND EXECUTE :CmdLine, :ReturnCode, :OutBufLen, :OutDataLen, :OutBuf, :CmdRetCode, :EnvGroup ; if (ReturnCode == p_rdb_RC_NORM) { /* if COMMAND EXECUTE terminates normally */ if (CmdRetCode!=0) { /* execution command error */ printf("pdrels command Error,Code = %d\n", CmdRetCode); printf("%s\n", OutBuf); } } else{ /* COMMAND EXECUTE error */ printf("COMMAND EXECUTE Error,Code = %d\n", ReturnCode); printf("%s\n", OutBuf); } } else { /* COMMAND EXECUTE error */ printf("COMMAND EXECUTE Error,Code = %d\n", ReturnCode); printf("%s\n", OutBuf); } return ; }
All Rights Reserved. Copyright (C) 2011, Hitachi, Ltd.