📄 myapi.pc
字号:
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* File name : PCS_RCV_BKHZML *
* Module ID : *
* Module Name : *
* Purpose : Get BKHZML Data from MQ 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 : *
* Date *
* Author *
* Reason For Change *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*/
#include "stdio.h"
#include <stdlib.h>
#include <sqlcpr.h>
#include "/usr/bkfx/include/Pcs_Rcv_BKHZML/cmdef.h"
#include "/usr/bkfx/include/Pcs_Rcv_BKHZML/Pcs_Rcv_BKHZML.h"
#include "/usr/bkfx/include/Pcs_Rcv_BKHZML/Function_define.h"
char *freememory;
/*define the global varible which will used in the function of ReadBufMsg()*/
long turn=0;
struct stBKMLDBRec_id stDBRecord_id;
int whichline=0;
char bkdh[8];
long lg_Key;
int init_time=0;
char Error_Flag = 0;
/*Get the Time_Interval specified in the file and return it */
int GetTimeInterval(char* cType)
{
FILE *hTimeInterval;
char cLine[MAX_LINE_LEN+1], cCaption[100], cValue[21];
int iInterval, i;
char* pLine;
hTimeInterval = fopen( CONFIG_FILE_FOR_TIMEINTERVAL, "r" );
if( hTimeInterval == NULL )
{
ProcessError(LOG_ERROR, "GetTimeInterval:Cannot open file %s,The file may not exist!", CONFIG_FILE_FOR_TIMEINTERVAL);
return(DEFAULT_TIMEINTERVAL);
}
while( myapi_ReadALine( cLine, hTimeInterval ) )
{
if( cLine[0] == '#' ) continue;
if( cLine[0] == NULL ) continue;
pLine = cLine;
while( (*pLine == ' ') || (*pLine == '\t') ) pLine++;
i=0;
while( (*pLine != ' ') && (*pLine != '\t') && (*pLine != '\0') )
{
cCaption[i] = *pLine;
i++;
pLine++;
}
cCaption[i] = '\0';
if( strcmp( cCaption, cType ) == 0 ) /*Match*/
{
while( (*pLine == ' ') || (*pLine == '\t') ) pLine++;
if( *pLine == '\0' )
{
fclose(hTimeInterval);
return(DEFAULT_TIMEINTERVAL);
}
i=0;
while( (*pLine != ' ') && (*pLine != '\t') && (*pLine != '\0') )
{
cValue[i] = *pLine;
i++;
pLine++;
}
cValue[i] = '\0';
iInterval = atoi(cValue);
if(iInterval <= 0)
{
fclose(hTimeInterval);
return(DEFAULT_TIMEINTERVAL);
}
else
{
fclose(hTimeInterval);
return(iInterval);
}
}
else
continue;
}
fclose( hTimeInterval );
return(DEFAULT_TIMEINTERVAL);
}
/*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;
if( i >= MAX_LINE_LEN ) i=0;
cLine[i] = '\0';
}
return(1);
}
/* connect to the database and initialize the errorlog file */
void Init()
{
/* 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
}
/* write the errorlog file when the database is wrong */
void sqlerror()
{
char ERR_CODE[10];
char Error_Msg[100];
EXEC SQL WHENEVER SQLERROR CONTINUE;
if (whichline == 0 )
{
ProcessError(LOG_ERROR, "database error:%s!", sqlca.sqlerrm.sqlerrmc );
sprintf(Error_Msg, "%ld", lg_Key);
ProcessError(LOG_NORMAL, "Didn't insert into DB sucessfully, message's jsxh is %s!", Error_Msg);
Error_Flag = 1;
}
else
{
if (Error_Flag != 1 )
{
ProcessError(LOG_ERROR, "database error:%s!", sqlca.sqlerrm.sqlerrmc );
sprintf(Error_Msg,"Its' jsxh is %ld, bkdh is %s!", lg_Key, bkdh);
ProcessError(LOG_NORMAL, "Didn't insert into DB sucessfully, %s!", Error_Msg);
}
}
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);
if ( freememory != NULL )
free( freememory );
MQBKClear();
EXEC SQL ROLLBACK RELEASE;
exit(1);
}
Init();
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 );
MQBKClear();
EXEC SQL ROLLBACK RELEASE;
exit(1);
}
void Read_Msg_to_Database(char *buf_data, int RecCount)
{
struct stBKMLDBRec stDBRecord;
struct BKMLMsgHeader MsgHeader;
char cElement[MAX_column_LEN];
int i, insert_count = 0;
char buf_HZ_Msg[HZ_MESSAGE_LEN];
turn = 0;
ReadBufMsg(buf_data, 10, cElement );
strcpy(buf_HZ_Msg, cElement );
MsgHeader.fsxh = (long)atol(cElement);
lg_Key = MsgHeader.fsxh;
ReadBufMsg(buf_data, 4, cElement );
MsgHeader.nf = (int)atoi(cElement);
ReadBufMsg(buf_data, 2, cElement );
strcpy(MsgHeader.sjbh, cElement );
CreateSndLogAndHZRec(MsgHeader.fsxh, CAPITAL_CODE);
InsertBKHZMLRec(MsgHeader.fsxh, MsgHeader.nf, CAPITAL_CODE );
for(i=0;i<RecCount;i++)
{
whichline++;
/* printf("i=%d\n",i);*/
ReadBufMsg(buf_data, 7, cElement );
trim(cElement);
strcpy(stDBRecord.bkdh, cElement );
strcpy(bkdh, stDBRecord.bkdh);
ReadBufMsg(buf_data, 40, cElement );
trim(cElement);
if (cElement[0] == '\0')
stDBRecord_id.bkmc_id = -1;
else
{
stDBRecord_id.bkmc_id = 0;
strcpy(stDBRecord.bkmc, cElement );
}
ReadBufMsg(buf_data, 16, cElement );
trim(cElement);
if (cElement[0] == '\0')
stDBRecord_id.fbkj_id = -1;
else
{
stDBRecord_id.fbkj_id = 0;
strcpy(stDBRecord.fbkj, cElement );
}
ReadBufMsg(buf_data, 10, cElement );
trim(cElement);
if (cElement[0] == '\0')
stDBRecord_id.cbrq_id = -1;
else
{
stDBRecord_id.cbrq_id = 0;
strcpy(stDBRecord.cbrq, cElement );
}
ReadBufMsg(buf_data, 6, cElement );
trim(cElement);
if (cElement[0] == '\0')
stDBRecord_id.dj_id = -1;
else
{
stDBRecord_id.dj_id = 0;
stDBRecord.dj = (float)atof(cElement);
}
ReadBufMsg(buf_data, 6, cElement );
trim(cElement);
if (cElement[0] == '\0')
stDBRecord_id.yj_id = -1;
else
{
stDBRecord_id.yj_id = 0;
stDBRecord.yj = (float)atof(cElement);
}
ReadBufMsg(buf_data, 6, cElement );
trim(cElement);
if (cElement[0] == '\0')
stDBRecord_id.jj_id = -1;
else
{
stDBRecord_id.jj_id = 0;
stDBRecord.jj = (float)atof(cElement);
}
ReadBufMsg(buf_data, 7, cElement );
trim(cElement);
if (cElement[0] == '\0')
stDBRecord_id.bnj_id = -1;
else
{
stDBRecord_id.bnj_id = 0;
stDBRecord.bnj = (float)atof(cElement);
}
ReadBufMsg(buf_data, 7, cElement );
trim(cElement);
if (cElement[0] == '\0')
stDBRecord_id.nj_id = -1;
else
{
stDBRecord_id.nj_id = 0;
stDBRecord.nj = (float)atof(cElement);
}
ReadBufMsg(buf_data, 24, cElement );
trim(cElement);
if (cElement[0] == '\0')
stDBRecord_id.hzddjdrq_id = -1;
else
{
stDBRecord_id.hzddjdrq_id = 0;
strcpy(stDBRecord.hzddjdrq, cElement );
}
ReadBufMsg(buf_data, 4, cElement );
trim(cElement);
if (cElement[0] == '\0')
stDBRecord_id.fxfw_id = -1;
else
{
stDBRecord_id.fxfw_id = 0;
strcpy(stDBRecord.fxfw, cElement );
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -