📄 pcsrestoreapi.pc
字号:
/*
* File name : PCSRestoreapi.pc
* Module ID : MD-P21-01
* Module Name : PCSRestore.c
* Purpose : Some functions called by PCSRestore.pc
* Author : Mr. Zhujingkun
* Date Created : 1999,07,29
* Version : Version 1.0
* Environment : Digital UNIX
* Portability : UNIX Platform
* Warnings : no
* References :
* Calling Syntax :
* Parameters :
* Returns :
* Calling Function:
* Called Functions: PCSRestore.pc
* Datastores and usages:
* Report : None
* Screens : None
* Messages Files : None
* Change Log :
* Change No. 01 :
*/
#include "stdio.h"
#include "stdlib.h"
#include "PCSRestore.h"
#include "PCSRestoreapi.h"
#include "sqlcpr.h"
/*Errorlog has been changed to ourselves
#include "errlog.h" */
/*
Read a line to a string from a file, \n is excluded.
return 1 if sucessful, 0 otherwise
Do not close the file.
*/
int myapi_ReadALine( char* cLine, FILE* hTable )
{
char cChar;
int i=0;
cLine[0] = '\0';
while( (cChar = fgetc( hTable )) != '\n' )
{
if( cChar == EOF ) return(0);
cLine[i++] = cChar;
/* truncated if superlong */
if( i >= MAX_LINE_LEN ) i=0;
cLine[i] = '\0';
}
return(1);
}
/*
*Record the error message into errorlog file
*Need to truncate or delete as the size grow
*/
void ErrorLog( const char* sErrorMessage )
{
FILE* hErrorFile;
char cDateTime[100];
hErrorFile = fopen( ERROR_LOG_FILE, "a" );
if( hErrorFile == NULL )
{
printf( "Critical! Cannot open ERROR_LOG_FILE for append or cannot create!\n");
return;
}
fseek( hErrorFile, 0, SEEK_END );
fputs( sErrorMessage, hErrorFile );
fclose( hErrorFile );
sprintf( cDateTime, "date >> %s\n", ERROR_LOG_FILE );
system( cDateTime );
}
/*
*Get the file size
*/
size_t GetFileSize( char *cFileName )
{
size_t ulSize;
FILE *hThisFile;
char cNextChar;
char cErrorMessage[500];
hThisFile = fopen( cFileName, "r" );
if( hThisFile == NULL )
{
/* ProcessError(LOG_ERROR, "PCSRestoreapi: GetFileSize- Cannot open the file: %s!\n",cFileName );*/
sprintf( cErrorMessage,"PCSRestoreapi: GetFileSize- Cannot open the file: %s!\n",cFileName );
ErrorLog( cErrorMessage );
return(0);
}
ulSize=0;
while( (cNextChar = fgetc(hThisFile)) != EOF ) ulSize++;
fclose( hThisFile );
return( ulSize );
}
/*
*Initialize the system resource used by this modual
*connect to the database and initialize the errorlog file
*/
void InitPCSRestore()
{
/* define the varible to connect to the database */
VARCHAR userid[20];
VARCHAR password[20];
strcpy( userid.arr, "PCSDBA" );
userid.len = strlen( userid.arr );
strcpy( password.arr, "DBA" );
password.len = strlen( password.arr );
EXEC SQL WHENEVER SQLERROR DO sqlerror();;
EXEC SQL CONNECT :userid IDENTIFIED BY :password;
printf("Connected to Oracle as user: %s\n\n\n", userid.arr );
}
/*
*Restore send log table and the associated tables from crash
*/
int SndLogRestore()
{
EXEC SQL BEGIN DECLARE SECTION;
long l_fsxh;
char c_sjfl;
EXEC SQL END DECLARE SECTION;
EXEC SQL DECLARE fsrz_cursor CURSOR FOR
SELECT FSXH, SJFL
FROM t_fsrz
WHERE SJZT=1; /*FSRZ_JSZ*/
EXEC SQL OPEN fsrz_cursor;
while(1)
{
EXEC SQL WHENEVER NOT FOUND DO break;
EXEC SQL FETCH fsrz_cursor
INTO :l_fsxh, :c_sjfl;
switch( c_sjfl )
{
case SJFL_ZDYS:
printf("Delete FS_ZDYS record.\n");
EXEC SQL DELETE FROM t_fszdyssj
WHERE FSXH = :l_fsxh;
EXEC SQL DELETE FROM t_fszdyssm
WHERE FSXH = :l_fsxh;
break;
case SJFL_PDYS:
printf("Delete FS_PDYS record.\n");
EXEC SQL DELETE FROM t_fspdyssj
WHERE FSXH = :l_fsxh;
EXEC SQL DELETE FROM t_fspdyssm
WHERE FSXH = :l_fsxh;
break;
case SJFL_BKML:
printf("Delete FS_BKML record.\n");
printf("FSXH=%li SJFL=%i\n", l_fsxh, c_sjfl);
EXEC SQL DELETE FROM t_fsbkjhmlnr
WHERE FSXH = :l_fsxh;
EXEC SQL DELETE FROM t_fsbkjhml
WHERE FSXH = :l_fsxh;
break;
case SJFL_BSFXBKML:
printf("Delete FS_BSFXBKML record.\n");
printf("FSXH=%li SJFL=%i\n", l_fsxh, c_sjfl);
EXEC SQL DELETE FROM t_fsbsfxmlnr
WHERE FSXH = :l_fsxh;
EXEC SQL DELETE FROM t_fsbsfxml
WHERE FSXH = :l_fsxh;
break;
case SJFL_ZFJ:
printf("Delete FS_ZFJ record, FSXH=%d.\n", l_fsxh);
EXEC SQL DELETE FROM t_fszfjbnr
WHERE FSXH = :l_fsxh;
EXEC SQL DELETE FROM t_fszfjb
WHERE FSXH = :l_fsxh;
break;
case SJFL_GH:
printf("Delete FS_GH record.\n");
EXEC SQL DELETE FROM t_fsgh
WHERE FSXH = :l_fsxh;
break;
case SJFL_TJBB:
printf("Delete FS_TJBB record.\n");
EXEC SQL DELETE FROM t_fstjbb
WHERE FSXH = :l_fsxh;
break;
case SJFL_YX:
printf("Delete FS_YX record.\n");
EXEC SQL DELETE FROM t_fsyxsj
WHERE FSXH = :l_fsxh;
EXEC SQL DELETE FROM t_zcfssj
WHERE FSXH = :l_fsxh;
break;
default:
break;
}
printf("delete HZ.\n");
/* EXEC SQL WHENEVER NOT FOUND CONTINUE; */
EXEC SQL DELETE FROM t_hz
WHERE FSXH=:l_fsxh;
}
EXEC SQL CLOSE fsrz_cursor;
EXEC SQL COMMIT WORK;
EXEC SQL WHENEVER NOT FOUND CONTINUE;
EXEC SQL DELETE FROM t_fsrz WHERE SJZT=1;
printf("everything is ok.\n");
EXEC SQL COMMIT WORK;
return(0);
}
/*
*Restore receive log table and the associated tables from crash
*/
int RcvLogRestore()
{
EXEC SQL BEGIN DECLARE SECTION;
long l_jsxh;
char c_sjfl;
EXEC SQL END DECLARE SECTION;
EXEC SQL DECLARE jsrz_cursor CURSOR FOR
SELECT JSXH, SJFL
FROM t_jsrz
WHERE SJZT=1; /*JSRZ_JSZ*/
EXEC SQL OPEN jsrz_cursor;
while(1)
{
EXEC SQL WHENEVER NOT FOUND DO break;
EXEC SQL FETCH jsrz_cursor
INTO :l_jsxh, :c_sjfl;
switch( c_sjfl )
{
case SJFL_ZDYS:
printf("Delete ZDYS record.\n");
EXEC SQL DELETE FROM t_jszdyssj
WHERE JSXH = :l_jsxh;
EXEC SQL DELETE FROM t_jszdyssm
WHERE JSXH = :l_jsxh;
break;
case SJFL_PDYS:
printf("Delete PDYS record.\n");
EXEC SQL DELETE FROM t_jspdyssj
WHERE JSXH = :l_jsxh;
EXEC SQL DELETE FROM t_jspdyssm
WHERE JSXH = :l_jsxh;
break;
case SJFL_BKML:
printf("Delete BKML record.\n");
printf("JSXH=%li SJFL=%i\n", l_jsxh, c_sjfl);
EXEC SQL DELETE FROM t_jsbkhzmlnr
WHERE JSXH = :l_jsxh;
EXEC SQL DELETE FROM t_jsbkhzml
WHERE JSXH = :l_jsxh;
break;
case SJFL_ZFJ:
printf("Delete ZFJ record.\n");
EXEC SQL DELETE FROM t_jszfjbnr
WHERE JSXH = :l_jsxh;
EXEC SQL DELETE FROM t_jszfjb
WHERE JSXH = :l_jsxh;
break;
case SJFL_GH:
printf("Delete GH record.\n");
EXEC SQL DELETE FROM t_jsgh
WHERE JSXH = :l_jsxh;
break;
case SJFL_YX:
printf("Delete YX record.\n");
EXEC SQL DELETE FROM t_jsyxsj
WHERE JSXH = :l_jsxh;
EXEC SQL DELETE FROM t_zcjssj
WHERE JSXH = :l_jsxh;
break;
default:
break;
}
}
EXEC SQL CLOSE jsrz_cursor;
EXEC SQL WHENEVER NOT FOUND CONTINUE;
EXEC SQL DELETE FROM t_jsrz WHERE SJZT=1;
printf("everything is ok.\n");
EXEC SQL COMMIT WORK RELEASE;
return(0);
}
/*
*Process individual files in temp directory from crash
*/
int RestoreIndividualFiles()
{
char cCommand[300];
FILE* hFileList;
char cThisLine[MAX_LINE_LEN+1], cThisItem[MAX_LINE_LEN+1];
char* pThisLine;
sprintf( cCommand, "ls %s > ./filelist", TEMP_DIR );
system( cCommand );
if( GetFileSize( "filelist" ) == 0 )
return(0);
hFileList = fopen( "filelist", "r" );
if( hFileList == NULL )
{
ErrorLog("PCSRestore: RestoreIndividualFiles- Open file error while restoring--\"filelist\"\n");
return(-1);
}
while( myapi_ReadALine( cThisLine, hFileList ) )
{
strcpy( cThisItem, cThisLine );
if( !strncmp( cThisItem, "BKML", 4 ) )
{
printf("Process BKJHML.\n");
sprintf( cThisItem, "%s/%s", TEMP_DIR, cThisItem );
if( fork() == 0 )
{
if( -1 == execl( "/usr/bkfx/bin/Pcs_Snd_BKJHML1.x","Pcs_Snd_BKJHML1.x", cThisItem, NULL ) );
printf("Pcs_Snd_BKJHML1.x not found.\n ");
exit(1);
}
}
else if( !strncmp( cThisItem, "YX", 2 ) )
{
printf("Process YX.\n");
sprintf( cThisItem, "%s/%s", TEMP_DIR, cThisItem );
if( fork() == 0 )
{
if( -1 == execl( "/usr/bkfx/bin/Pcs_Snd_YX1.x","Pcs_Snd_YX1.x", cThisItem, NULL ) );
printf("Pcs_Snd_YX1.x not found.\n ");
exit(1);
}
}
else if( !strncmp( cThisItem, "BSFX", 4 ) )
{
printf("Process BSFX.\n");
sprintf( cThisItem, "%s/%s", TEMP_DIR, cThisItem );
if( fork() == 0 )
{
if( -1 == execl( "/usr/bkfx/bin/Pcs_Snd_BSFX1.x","Pcs_Snd_BSFX1.x", cThisItem, NULL ) );
printf("Pcs_Snd_BSFX1.x not found.\n ");
exit(1);
}
}
else if( !strncmp( cThisItem, "SNML", 4 ) )
{
printf("Process SNML.\n");
sprintf( cThisItem, "%s/%s", TEMP_DIR, cThisItem );
if( fork() == 0 )
{
if( -1 == execl( "/usr/bkfx/bin/Pcs_Snd_SNML.x","Pcs_Snd_SNML.x", cThisItem, NULL ) );
printf("Pcs_Snd_SNML.x not found.\n ");
exit(1);
}
}
else if( !strncmp( cThisItem, "GH", 2 ) )
{
printf(" Process GH.\n" );
if( fork() == 0 )
{
if( -1 == execl( "Pcs_Snd_GH1.x", cThisItem, NULL ) );
printf("PCS_Snd_GH.x not found.\n ");
exit(1);
}
}
else if( !strncmp( cThisItem, "TJBB", 4 ) )
{
printf(" Process TJBB.\n" );
if( fork() == 0 )
{
if( -1 == execl( "Pcs_Snd_TJBB1.x", cThisItem, NULL ) );
printf("PCS_Snd_TJBB.x not found.\n ");
exit(1);
}
}
else if( !strncmp( cThisItem, "ZFJB", 4 ) )
{
printf(" Process ZFJB.\n" );
if( fork() == 0 )
{
if( -1 == execl( "Pcs_Snd_ZFJB1.x", cThisItem, NULL ) );
printf("Pcs_Snd_ZFJB1.x not found.\n ");
exit(1);
}
}
else if( (!strncmp( cThisItem, "BZZY", 4 )) || (!strncmp( cThisItem, "BZJY", 4 )) \
|| (!strncmp( cThisItem, "BPZY", 4 )) || (!strncmp( cThisItem, "BPJY", 4 )) \
|| (!strncmp( cThisItem, "KZZY", 4 )) || (!strncmp( cThisItem, "KZJY", 4 )) \
|| (!strncmp( cThisItem, "KPZY", 4 )) || (!strncmp( cThisItem, "KPJY", 4 )))
{
printf(" Process YSSM.\n" );
if( fork() == 0 )
{
if( -1 == execl( "Pcs_Snd_YS1.x", cThisItem, NULL ) );
printf("Pcs_Snd_YS1.x not found.\n ");
exit(1);
}
}
else
{
printf("process other file.\n");
sprintf( cCommand, "mv %s/%s %s/%s\n", TEMP_DIR, cThisItem, GARBAGE_DIR, cThisItem );
system( cCommand );
}
}
return(0);
}
/*
*Release system resource after procession
*/
void EndPCSRestore()
{
/* CloseErrLogObj();*/
}
/*
*Processions taken when SQL Error occurs
*/
void sqlerror()
{
EXEC SQL WHENEVER SQLERROR CONTINUE;
printf("\nOracle error detected.\n");
printf("\n%.70s \n", sqlca.sqlerrm.sqlerrmc);
EXEC SQL ROLLBACK WORK;
/*exit(1);*/
}
/*
*Called when system administrator kill the process
*function: Release memory, close file handle, disconnect database, etc.
*/
void Terminate()
{
EXEC SQL ROLLBACK RELEASE;
/* CloseErrLogObj();*/
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -