📄 myapi.pc
字号:
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* File name : PCS_Snd_TJBB1.x *
* Module ID : *
* Module Name : *
* Purpose : Get TJBB Data from TJBBFILE And Insert into DB *
* Author : Mr. laishihong *
* Date Created : 1999,07,14 *
* Version : Version 1.0 *
* Environment : Digital UNIX *
* Portability : UNIX Platform *
* Warnings : *
* References : *
* Calling Syntax : *
* Parameters : None *
* Returns : void *
* Calling Function: *
* Called Functions: When system startup *
* Datastores and usages: * *
* (a) Input *
* (b) OutPut *
* Report : None *
* Screens : None *
* Messages Files : None *
* Change Log : *
* Change No. *
* Date *
* Author *
* Reason For Change *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*/
#include "stdio.h"
#include <stdlib.h>
#include <sqlcpr.h>
#include "/usr/bkfx/include/Pcs_Snd_TJBB1/cmdef.h"
#include "/usr/bkfx/include/Pcs_Snd_TJBB1/Pcs_Snd_TJBB1.h"
#include "/usr/bkfx/include/Pcs_Snd_TJBB1/Function_define.h"
char *freememory;
FILE *FreeFileHandle;
char filename[MAX_LINE_LEN];
int init_time=0;
/* connect to the database and initialize the errorlog file */
void InitSndTJBB1()
{
/* 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;
/*#ifdef DEBUG*/
ProcessError(LOG_NORMAL, "Connected to Oracle as user:%s!", userid.arr);
/*#endif*/
}
/* get the relative information from the data file name */
void myapi_GetInfoFromFileName( struct stTJBBInfo *stTJBBRecord, char *cFileName )
{
char cname[200], cExt[5];
char *pFileName;
int i = 0;
char nf[5];
char yf[3];
pFileName = cFileName;
while( *pFileName != '\0' )
{
cname[i++] = *pFileName++;
if( i==199 )
{
ProcessError(LOG_ERROR,"The file name string is too long!",END);
break;
}
}
cname[i] = '\0';
stTJBBRecord->TJBB_Code[0] = cname[i-8];
stTJBBRecord->TJBB_Code[1] = cname[i-7];
stTJBBRecord->TJBB_Code[2] = '\0';
yf[0] = cname[i-6];
yf[1] = cname[i-5];
yf[2] = '\0';
stTJBBRecord->yf = (int)atoi(yf);
EXEC SQL SELECT TO_CHAR(SYSDATE, 'YYYY') INTO :nf FROM SYS.DUAL;
if (cname[i-1] =='0')
{
if ((atoi(nf))%2 == 1)
stTJBBRecord->nf = atoi(nf) + 1;
else
stTJBBRecord->nf = atoi(nf);
}
else if (cname[i-1] =='1')
{
if ((atoi(nf))%2 == 0)
stTJBBRecord->nf = atoi(nf) + 1;
else
stTJBBRecord->nf = atoi(nf);
}
else
ProcessError(LOG_ERROR,"The file name must be incorrect! please retry after modify it.",END);
}
/* get the file size */
size_t myapi_GetFileSize( FILE *hTable )
{
size_t ulSize;
char cNextChar;
ulSize=0;
while( (cNextChar = fgetc( hTable )) != EOF ) ulSize++;
rewind(hTable);
return( ulSize );
}
/* read the file data into the buffer */
void ReadTJBBFileData(FILE* hTable, size_t Length, char *buf_data)
{
if( fread(buf_data, Length , 1, hTable) != 1)
{
if(feof(hTable))
{ ProcessError(LOG_ERROR,"Premature end of file.",END);
free( freememory );
fclose(FreeFileHandle);
movefile();
EXEC SQL ROLLBACK RELEASE;
exit (1);
}
else
{
ProcessError(LOG_ERROR,"file read error!",END);
free( freememory );
fclose(FreeFileHandle);
movefile();
EXEC SQL ROLLBACK RELEASE;
exit (1);
}
}
}
/*insert a record into the t_fsrz and t_hz table */
int CreateSndLogAndHZRec(long lg_Key, char *pc)
{
char sjfl = SJFL_TJBB;
char sjzt = FSRZ_UNDER_RCV;
char hzzt = HZ_NOT_SND;
char sjbh[3];
int pcxx;
char bz = '\0';
pcxx = atoi(pc);
strcpy(sjbh, CAPITAL_CODE);
EXEC SQL WHENEVER SQLERROR DO sqlerror();
EXEC SQL INSERT INTO T_FSRZ VALUES (:lg_Key, :sjfl, :sjzt, SYSDATE );
EXEC SQL INSERT INTO T_HZ VALUES (SYSDATE, :sjbh, :hzzt, :lg_Key, :bz, :pcxx);
/*EXEC SQL COMMIT WORK;*/
return(1);
}
/* write the errorlog file when the database is wrong */
void sqlerror()
{
char ERR_CODE[10];
EXEC SQL WHENEVER SQLERROR CONTINUE;
ProcessError(LOG_ERROR, "database error:%s!", sqlca.sqlerrm.sqlerrmc );
ProcessError(LOG_ERROR, "Didn't insert into DB successfully!", END);
strncpy(ERR_CODE,sqlca.sqlerrm.sqlerrmc,9);
ERR_CODE[9]='\0';
if( strcmp(ERR_CODE,"ORA-03127")==0|| strcmp(ERR_CODE,"ORA-03114")==0|| strcmp(ERR_CODE,"ORA-03123")==0|| strcmp(ERR_CODE,"ORA-01034")==0|| strcmp(ERR_CODE,"ORA-01089")==0||strcmp(ERR_CODE,"ORA-01012")==0||strcmp(ERR_CODE,"ORA-01089") ==0||strcmp( ERR_CODE, "ORA-01033") ==0 )
{
sleep(INIT_INTERVAL);
init_time++;
if (init_time == 6)
{
ProcessError(LOG_NORMAL, "Could not connect to the database, so exit now!",END);
ProcessError(LOG_NORMAL, "Please reload the data again!",END);
if ( freememory != NULL )
free( freememory );
fclose( FreeFileHandle );
EXEC SQL ROLLBACK RELEASE;
movefile();
exit(1);
}
InitSndTJBB1();
return;
}
return;
}
/* free the memory and close the file etc. */
void terminate()
{
ProcessError(LOG_NORMAL, "The application is terminated by user!",END);
if ( freememory != NULL )
free( freememory );
fclose( FreeFileHandle );
EXEC SQL ROLLBACK RELEASE;
movefile();
exit(1);
}
/* Read the buffer to the structure, return 1 if sucessful*/
int myapi_FillFileRecord( char* FileLength, struct stTJBBInfo *stTJBBRecord )
{
long i=0;
long j=0;
while ( FileLength[j] != '\0' )
{
stTJBBRecord->bbnr[i++] = FileLength[j++];
/* truncated if superlong */
if( i >= MAX_LINE_LEN ) i=0;
}
stTJBBRecord->bbnr[i] = '\0';
return(1);
}
/* insert the record into the t_fstjbb table */
int InsertSndTJBBRec(struct stTJBBInfo *stTJBBRecord )
{
EXEC SQL WHENEVER SQLERROR DO sqlerror();
EXEC SQL INSERT INTO T_FSTJBB VALUES (:stTJBBRecord);
EXEC SQL COMMIT WORK;
return(1);
}
/* update the table to locate the relative flag */
int UpdateSndLogRecStatus(long lg_Key)
{
char sjzt = FSRZ_WAITFOR_SND;
EXEC SQL WHENEVER SQLERROR DO sqlerror();
EXEC SQL UPDATE T_FSRZ SET SJZT = :sjzt, JSSJ = SYSDATE
WHERE FSXH = :lg_Key;
EXEC SQL COMMIT WORK RELEASE;
return(1);
}
void ProcessError( char *LOG, char *sErrorMessage1, char *sErrorMessage2 )
{
FILE* hErrorFile;
char cDateTime[100],tempstr[100];
int i,j,len,n;
long filesize;
char bakfile[100];
tempstr[0]='\0';
len=strlen(sErrorMessage1);
for(i=0;i<=len;i++)
{
if(sErrorMessage1[i]=='%')
{
n=i;
if(len!=i+1)
{
for(j=0;j<200&&sErrorMessage1[i+2]!='\0';j++,i++)
tempstr[j]=sErrorMessage1[i+2];
tempstr[j]='\0';
}
break;
}
if(sErrorMessage1[i]=='\0')
{
n=i;
tempstr[0] = '\0';
break;
}
}
sErrorMessage1[n]='\0';
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 );
filesize = ftell(hErrorFile);
if (filesize > 5242880)
{
fclose(hErrorFile );
sprintf(bakfile, "mv %s %s.bak", ERROR_LOG_FILE, ERROR_LOG_FILE);
system(bakfile);
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( "\n",hErrorFile);
fputs( LOG ,hErrorFile);
printf("\n%s",LOG);
fputs( sErrorMessage1,hErrorFile );
printf("%s",sErrorMessage1);
fputs( sErrorMessage2,hErrorFile );
printf("%s",sErrorMessage2);
fputs( tempstr,hErrorFile );
printf("%s\n",tempstr);
fputs( "\n",hErrorFile);
fclose( hErrorFile );
sprintf( cDateTime, "date >> %s\n", ERROR_LOG_FILE );
system( cDateTime );
system( "date");
}
void movefile()
{
char cCommand[MAX_LINE_LEN];
/* move the source fsbkjhml data file to the backup directory*/
sprintf( cCommand, "mv -f %s %s", filename, BACKUP_DIRECTORY );
system( cCommand );
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -