⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 myapi.pc

📁 unix 下用pro*c tuxedo 开发的东西
💻 PC
📖 第 1 页 / 共 2 页
字号:
/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
*	File name		: Pcs_Snd_BKJHML1.pc	                       *				
*	Module ID		:				               *
*	Module Name	:                                                      *
*	Purpose		: Get BKML Data from BKMLFILE 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_BKJHML1/cmdef.h"
#include "/usr/bkfx/include/Pcs_Snd_BKJHML1/Pcs_Snd_BKJHML1.h"
#include "/usr/bkfx/include/Pcs_Snd_BKJHML1/Function_define.h"

/*define the global varible which will used in the function of myapi_ReadALine()*/ 
long turn=0;
struct stBKMLDBRec_id stDBRecord_id;
char filename[MAX_LINE_LEN];

/*define the global varible which will get the sequence number*/
unsigned long lg_Key;
int init_time = 0;
int whichline;
char bkdh[8];

char *freememory;
FILE *FreeFileHandle;

/* connect to the database and initialize the errorlog file */
void InitSndBKJHML1()
{
	/* 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 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 ReadBKMLFileData(FILE* hTable, size_t Length, char *buf_data)
{
	char *sDescription;
	
	if( fread(buf_data, Length , 1, hTable) != 1)
	{
		if(feof(hTable)) 
		{
			ProcessError(LOG_ERROR,"ReadBKMLFileData function:Premature end of file.",END);
			free( freememory );
			fclose(FreeFileHandle);
			movefile();
			EXEC SQL ROLLBACK RELEASE;
			exit (1);
		}
		else 
		{
			ProcessError(LOG_ERROR,"ReadBKMLFileData function: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(char *pc)
{
	char datatype = SJFL_BKMM;
	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, :datatype, :sjzt, SYSDATE );
	EXEC SQL INSERT INTO T_HZ VALUES (SYSDATE, :sjbh, :hzzt, :lg_Key, :bz, :pcxx);
	return(1);
}

/* write the errorlog file when the database is wrong */
void sqlerror()
{
	char ERR_CODE[10];
	char Error_Msg[100];

	EXEC SQL WHENEVER SQLERROR CONTINUE;
	ProcessError(LOG_ERROR,   "database error:%s!", sqlca.sqlerrm.sqlerrmc );
	sprintf(Error_Msg,"line: %d and bkdh: %s", whichline, 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);
			sprintf(Error_Msg,"%d",whichline);
			ProcessError(LOG_NORMAL, "Please reload the data from the line %s!",Error_Msg);
			if ( freememory != NULL )
			free( freememory );
			fclose( FreeFileHandle );
			EXEC SQL ROLLBACK RELEASE;
			movefile();
			exit(1);
		}
		InitSndBKJHML1();
		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);
}

/* insert a record into the t_fsbkjhml table */
int InsertBKJHMLRec() 
{	
	char nf_char[5];
	int nf;
	
	EXEC SQL WHENEVER SQLERROR DO sqlerror();
	EXEC SQL SELECT TO_CHAR(SYSDATE, 'YYYY') INTO :nf_char FROM SYS.DUAL;
	
	nf_char[4]='\0';
	nf = (int)atoi(nf_char) +1;
	
	EXEC SQL INSERT INTO T_FSBKJHML VALUES (:nf, :lg_Key);
	EXEC SQL COMMIT WORK;
	return(1);
}

/* Read a line to a string from the buffer , \n is excluded.
   return 1 if sucessful, 0 when the end of the buffer */
int myapi_ReadALine( char* cLine, char* FileLength )
{
	
	int i=0;
	cLine[0] = '\0';

	while (FileLength[turn] =='\n')
	turn++;
	while( FileLength[turn] !='\n')
	{
		if( FileLength[turn] == '\0' ) 
		return(0);
		cLine[i++] = FileLength[turn++];
		
		/* truncated if superlong */
		if( i >= MAX_LINE_LEN ) i=0;
		cLine[i] = '\0';
	}
	turn++;
	return(1);
}

/* depart the string to fill the fsbkjhml record 
   return 1 if the string is a legal record, 0 otherwise */
int myapi_FillFileRecord( char *cLine, struct stBKMLFileRec *stFileRecord )
{
	char *pLine;
	char cElement[MAX_LINE_LEN+1];
	int i,j;
	
	pLine = cLine;
	i=0;
	j=0;
	while( *pLine != '\0' )
	{
		if(*pLine != ',')
		{
			cElement[j++] = *pLine;
		}
		else
		{
			
			cElement[j] = '\0';
			j=0;
			i++;
#ifdef DEBUG
			printf( "%i	%s\n", i, cElement );
#endif			
			switch(i)
			{
			     case 1:
			    	strncpy( stFileRecord->bkdh, cElement, 8 );
				strcpy( bkdh, stFileRecord->bkdh );
			    	break;
			    case 2:
			    	strncpy( stFileRecord->bkmc, cElement, 41 );
			    	if (cElement[0] == '\0')
			    	{
			    		stDBRecord_id.bkmc_id = -1;
			    		break;
			    	}
			    	stDBRecord_id.bkmc_id = 0;
			    	break;
			    case 3:
			    	strncpy( stFileRecord->fbkjmc, cElement, 17 );
			    	if (cElement[0] == '\0')
			    	{
			    		stDBRecord_id.fbkjmc_id = -1;
			    		break;
			    	}
			    	stDBRecord_id.fbkjmc_id = 0;
			    	break;
			    case 4:
			    	strncpy( stFileRecord->cbrq, cElement, 11 );
			    	if (cElement[0] == '\0')
			    	{
			    		stDBRecord_id.cbrq_id = -1;
			    		break;
			    	}
			    	stDBRecord_id.cbrq_id = 0;
			    	break;
			    case 5:
			    	stFileRecord->dj = (float)atof(cElement);
			    	if (cElement[0] == '\0')
			    	{
			    		stDBRecord_id.dj_id = -1;
			    		break;
			    	}
			    	stDBRecord_id.dj_id = 0;
			    	break;
			    case 6:
			    	stFileRecord->yj = (float)atof(cElement);
			    	if (cElement[0] == '\0')
			    	{
			    		stDBRecord_id.yj_id = -1;
			    		break;
			    	}
			    	stDBRecord_id.yj_id = 0;
			    	break;
			    case 7:
			    	stFileRecord->jj = (float)atof(cElement);
			    	if (cElement[0] == '\0')
			    	{
			    		stDBRecord_id.jj_id = -1;
			    		break;
			    	}
			    	stDBRecord_id.jj_id = 0;
			    	break;
			    case 8:
			    	stFileRecord->bnj = (float)atof(cElement);
			    	if (cElement[0] == '\0')

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -