📄 pcs_input_bsbh.c
字号:
NAME
SQLCA : SQL Communications Area.
FUNCTION
Contains no code. Oracle fills in the SQLCA with status info
during the execution of a SQL stmt.
NOTES
**************************************************************
*** ***
*** This file is SOSD. Porters must change the data types ***
*** appropriately on their platform. See notes/pcport.doc ***
*** for more information. ***
*** ***
**************************************************************
If the symbol SQLCA_STORAGE_CLASS is defined, then the SQLCA
will be defined to have this storage class. For example:
#define SQLCA_STORAGE_CLASS extern
will define the SQLCA as an extern.
If the symbol SQLCA_INIT is defined, then the SQLCA will be
statically initialized. Although this is not necessary in order
to use the SQLCA, it is a good pgming practice not to have
unitialized variables. However, some C compilers/OS's don't
allow automatic variables to be init'd in this manner. Therefore,
if you are INCLUDE'ing the SQLCA in a place where it would be
an automatic AND your C compiler/OS doesn't allow this style
of initialization, then SQLCA_INIT should be left undefined --
all others can define SQLCA_INIT if they wish.
If the symbol SQLCA_NONE is defined, then the SQLCA variable will
not be defined at all. The symbol SQLCA_NONE should not be defined
in source modules that have embedded SQL. However, source modules
that have no embedded SQL, but need to manipulate a sqlca struct
passed in as a parameter, can set the SQLCA_NONE symbol to avoid
creation of an extraneous sqlca variable.
MODIFIED
jbasu 12/12/94 - Bug 217878: note this is an SOSD file
losborne 08/11/92 - No sqlca var if SQLCA_NONE macro set
Clare 12/06/84 - Ch SQLCA to not be an extern.
Clare 10/21/85 - Add initialization.
Bradbury 01/05/86 - Only initialize when SQLCA_INIT set
Clare 06/12/86 - Add SQLCA_STORAGE_CLASS option.
*/
#ifndef SQLCA
#define SQLCA 1
struct sqlca
{
/* ub1 */ char sqlcaid[8];
/* b4 */ long sqlabc;
/* b4 */ long sqlcode;
struct
{
/* ub2 */ unsigned short sqlerrml;
/* ub1 */ char sqlerrmc[70];
} sqlerrm;
/* ub1 */ char sqlerrp[8];
/* b4 */ long sqlerrd[6];
/* ub1 */ char sqlwarn[8];
/* ub1 */ char sqlext[8];
};
#ifndef SQLCA_NONE
#ifdef SQLCA_STORAGE_CLASS
SQLCA_STORAGE_CLASS struct sqlca sqlca
#else
struct sqlca sqlca
#endif
#ifdef SQLCA_INIT
= {
{'S', 'Q', 'L', 'C', 'A', ' ', ' ', ' '},
sizeof(struct sqlca),
0,
{ 0, {0}},
{'N', 'O', 'T', ' ', 'S', 'E', 'T', ' '},
{0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0},
{0, 0, 0, 0, 0, 0, 0, 0}
}
#endif
;
#endif
#endif
/* end SQLCA */
/* EXEC SQL WHENEVER SQLERROR GOTO sqlerror; */
/*****************************
| Connect to DataBase |
*****************************/
strcpy( userid.arr,"pcsdba");
userid.len = strlen (userid.arr);
strcpy( password.arr,"dba");
password.len = strlen( password.arr);
/* EXEC SQL CONNECT :userid IDENTIFIED BY :password; */
{
struct sqlexd sqlstm;
sqlstm.sqlvsn = 8;
sqlstm.arrsiz = 3;
sqlstm.iters = (unsigned int )10;
sqlstm.offset = (unsigned int )16;
sqlstm.cud = sqlcud0;
sqlstm.sqlest = (unsigned char *)&sqlca;
sqlstm.sqlety = (unsigned short)0;
sqlstm.sqhstv[0] = (unsigned char *)&userid;
sqlstm.sqhstl[0] = (unsigned int )12;
sqlstm.sqindv[0] = ( short *)0;
sqlstm.sqharm[0] = (unsigned int )0;
sqlstm.sqhstv[1] = (unsigned char *)&password;
sqlstm.sqhstl[1] = (unsigned int )12;
sqlstm.sqindv[1] = ( short *)0;
sqlstm.sqharm[1] = (unsigned int )0;
sqlstm.sqphsv = sqlstm.sqhstv;
sqlstm.sqphsl = sqlstm.sqhstl;
sqlstm.sqpind = sqlstm.sqindv;
sqlstm.sqparm = sqlstm.sqharm;
sqlstm.sqparc = sqlstm.sqharc;
sqlcxt((void **)0, &sqlctx, &sqlstm, &sqlfpn);
if (sqlca.sqlcode < 0) goto sqlerror;
}
return (1);
sqlerror:
ProcessError(LOG_ERROR,"Connect To DataBase SQL Error!");
/* EXEC SQL RollBack; */
{
struct sqlexd sqlstm;
sqlstm.sqlvsn = 8;
sqlstm.arrsiz = 3;
sqlstm.iters = (unsigned int )1;
sqlstm.offset = (unsigned int )42;
sqlstm.cud = sqlcud0;
sqlstm.sqlest = (unsigned char *)&sqlca;
sqlstm.sqlety = (unsigned short)0;
sqlcxt((void **)0, &sqlctx, &sqlstm, &sqlfpn);
if (sqlca.sqlcode < 0) goto sqlerror;
}
return(-1);
}
int Read_BSBH_File(char *file_name )
{
int len_bsbh_file;
fp = fopen(file_name,"r");
if (fp == NULL)
{
ProcessError(LOG_ERROR,"Pcs_Input_BSBH.x: Open BSBH \
File Error!",END);
return(-1);
}
file_name = file_name + mypath(file_name);
fseek( fp,0,2);
len_bsbh_file = ftell( fp);
buf_bsbh = ( char * )malloc( len_bsbh_file + 1);
if (buf_bsbh == NULL)
{
ProcessError(LOG_ERROR,"Pcs_Input_BSBH.x: Malloc BSBH \
Buffer Error!",END);
return ( -1);
}
memset( buf_bsbh, '\0', len_bsbh_file + 1 );
fseek( fp,0,0);
fread( buf_bsbh,len_bsbh_file,1,fp );
fclose( fp );
tmp = buf_bsbh;
return(1);
}
int Insert_BSBH_DB()
{
char bsbh[3], bsmc[9];
int i = 0, j = 0, comma = 0, p = 0;
while ( buf_bsbh[p] != '\0' )
{
if ( buf_bsbh[p] == ',' )
{
comma++;
if ( comma%2 == 1 )
{
bsbh[i] = '\0';
i = 0;
}
else
{
bsmc[j] = '\0';
j = 0;
}
if ( comma%2 == 0 )
{
/* EXEC SQL WHENEVER SQLERROR GOTO sqlerror; */
#ifdef DEBUG
printf("bsbh,bsmc is %s,%s\n",bsbh,\
bsmc);
#endif
/* EXEC SQL INSERT INTO T_BSBH
VALUES (:bsbh, :bsmc ); */
{
struct sqlexd sqlstm;
sqlstm.sqlvsn = 8;
sqlstm.arrsiz = 3;
sqlstm.stmt = "insert into T_BSBH values (:b0,:b1)";
sqlstm.iters = (unsigned int )1;
sqlstm.offset = (unsigned int )56;
sqlstm.cud = sqlcud0;
sqlstm.sqlest = (unsigned char *)&sqlca;
sqlstm.sqlety = (unsigned short)0;
sqlstm.sqhstv[0] = (unsigned char *)bsbh;
sqlstm.sqhstl[0] = (unsigned int )3;
sqlstm.sqindv[0] = ( short *)0;
sqlstm.sqharm[0] = (unsigned int )0;
sqlstm.sqhstv[1] = (unsigned char *)bsmc;
sqlstm.sqhstl[1] = (unsigned int )9;
sqlstm.sqindv[1] = ( short *)0;
sqlstm.sqharm[1] = (unsigned int )0;
sqlstm.sqphsv = sqlstm.sqhstv;
sqlstm.sqphsl = sqlstm.sqhstl;
sqlstm.sqpind = sqlstm.sqindv;
sqlstm.sqparm = sqlstm.sqharm;
sqlstm.sqparc = sqlstm.sqharc;
sqlcxt((void **)0, &sqlctx, &sqlstm, &sqlfpn);
if (sqlca.sqlcode < 0) goto sqlerror;
}
}
}
else
{
if ( isspace( buf_bsbh[p] ) == 0 )
{
if ( comma%2 == 0 )
{
bsbh[i] = buf_bsbh[p];
i++;
}
else
{
bsmc[j] = buf_bsbh[p];
j++;
}
}
}
buf_bsbh[p++];
}
free( tmp );
/* EXEC SQL COMMIT; */
{
struct sqlexd sqlstm;
sqlstm.sqlvsn = 8;
sqlstm.arrsiz = 3;
sqlstm.iters = (unsigned int )1;
sqlstm.offset = (unsigned int )78;
sqlstm.cud = sqlcud0;
sqlstm.sqlest = (unsigned char *)&sqlca;
sqlstm.sqlety = (unsigned short)0;
sqlcxt((void **)0, &sqlctx, &sqlstm, &sqlfpn);
if (sqlca.sqlcode < 0) goto sqlerror;
}
return(1);
sqlerror:
ProcessError(LOG_ERROR,"Pcs_Input_BSBH.x: Running Function \
Insert_BSBH_DB() SQL Error!",END);
free( tmp );
/* EXEC SQL ROLLBACK; */
{
struct sqlexd sqlstm;
sqlstm.sqlvsn = 8;
sqlstm.arrsiz = 3;
sqlstm.iters = (unsigned int )1;
sqlstm.offset = (unsigned int )92;
sqlstm.cud = sqlcud0;
sqlstm.sqlest = (unsigned char *)&sqlca;
sqlstm.sqlety = (unsigned short)0;
sqlcxt((void **)0, &sqlctx, &sqlstm, &sqlfpn);
if (sqlca.sqlcode < 0) goto sqlerror;
}
return (-1);
}
int End_PCS_Input_BSBH()
{
/* EXEC SQL WHENEVER SQLERROR GOTO sqlerror; */
/* EXEC SQL COMMIT WORK RELEASE; */
{
struct sqlexd sqlstm;
sqlstm.sqlvsn = 8;
sqlstm.arrsiz = 3;
sqlstm.iters = (unsigned int )1;
sqlstm.offset = (unsigned int )106;
sqlstm.cud = sqlcud0;
sqlstm.sqlest = (unsigned char *)&sqlca;
sqlstm.sqlety = (unsigned short)0;
sqlcxt((void **)0, &sqlctx, &sqlstm, &sqlfpn);
if (sqlca.sqlcode < 0) goto sqlerror;
}
return(1);
sqlerror:
ProcessError(LOG_ERROR,"Pcs_Input_BSBH.x: Running Function \
End_PCS_Input_BSBH() SQL Error!",END);
/* EXEC SQL RollBack RELEASE; */
{
struct sqlexd sqlstm;
sqlstm.sqlvsn = 8;
sqlstm.arrsiz = 3;
sqlstm.iters = (unsigned int )1;
sqlstm.offset = (unsigned int )120;
sqlstm.cud = sqlcud0;
sqlstm.sqlest = (unsigned char *)&sqlca;
sqlstm.sqlety = (unsigned short)0;
sqlcxt((void **)0, &sqlctx, &sqlstm, &sqlfpn);
if (sqlca.sqlcode < 0) goto sqlerror;
}
return(-1);
}
int mypath( char *filename )
{
int len, i;
len = strlen(filename);
for( i = len-1 ; i >= 0 ; i-- )
if( filename[i] == '/' ) break;
return (i+1);
}
void ProcessError( char *LOG, char *sErrorMessage1, char *sErrorMessage2 )
{
FILE* hErrorFile;
char cDateTime[100],tempstr[100];
int i,j,len,n;
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 );
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 );
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -