📄 oracom.pc
字号:
#include "../h/ora.h"
#include "sqlca.h"
#include "oraca.h"
int ConnectDB( char *dbname, char *sid )
{
EXEC SQL BEGIN DECLARE SECTION;
char _DbName[80], _PassWd[80], _DbSid[80];
EXEC SQL END DECLARE SECTION;
strcpy( _DbName, dbname );
strcpy( _DbSid, sid );
sprintf( tmpss, "Connect Oracle %s@%s ......", _DbName, _DbSid );
PTrace( DEBUG, tmpss );
EXEC SQL CONNECT :_DbName IDENTIFIED BY :_PassWd using :_DbSid;
if ( sqlca.sqlcode )
{
strcpy( tmpss, "Connect Result : Fail " );
PTrace( SQLDEBUG, tmpss );
return ( -1);
}
strcpy( tmpss, "Connect Result : Success " );
PTrace( DEBUG, tmpss );
return (0);
}
int Search_Module( int id, char *localnet )
{
int i;
EXEC SQL BEGIN DECLARE SECTION;
int _Mid;
char _LNet[80], _IN_MDir[200], _OUT_MDir[200];
char _IN_TName[80], _OUT_TName[80];
EXEC SQL END DECLARE SECTION;
_Mid = id;
strncpy( _LNet, localnet, 2 );
_LNet[2] = 0;
EXEC SQL SELECT MODULE_INPUT_TAB, MODULE_OUTPUT_TAB, MODULE_INPUT_DIR,
MODULE_OUTPUT_DIR INTO :_IN_TName, :_OUT_TName, :_IN_MDir,:_OUT_MDir FROM MODULE_DEFINE
WHERE LOCAL_CODE = :_LNet AND MODULE_ID = :_Mid;
if ( sqlca.sqlcode )
{
sprintf( tmpss, "Search Module %s %d Err!", _LNet, _Mid );
PTrace( SQLDEBUG, tmpss );
return ( -1);
}
strcpy( IN_TName, _IN_TName );
strcpy( OUT_TName, _OUT_TName );
strcpy( IN_MDir, _IN_MDir );
strcpy( OUT_MDir, _OUT_MDir );
DeleteSpace( IN_TName );
DeleteSpace( OUT_TName );
DeleteSpace( IN_MDir );
DeleteSpace( OUT_MDir );
i = strlen( IN_MDir );
if ( IN_MDir[i - 1] != '/' )
{
IN_MDir[i] = '/';
IN_MDir[i + 1] = 0;
}
i = strlen( OUT_MDir );
if ( OUT_MDir[i - 1] != '/' )
{
OUT_MDir[i] = '/';
OUT_MDir[i + 1] = 0;
}
return (0);
}
int Search_Local_Exchange( char *_lnet )
{
int i, j, l;
EXEC SQL BEGIN DECLARE SECTION;
char _LNet[20];
char _ecode[100][10], _XDir[100][201];
int _EId[100];
EXEC SQL END DECLARE SECTION;
strcpy( _LNet, _lnet );
EXEC SQL SELECT EXCHANGE_CODE, SWITCH_TYPE_ID, WORK_PATH INTO _ecode, _EId,:_XDir
from LOCAL_EXCHANGE WHERE LOCAL_CODE = :_LNet;
if ( sqlca.sqlcode && sqlca.sqlcode != 1403 )
{
sprintf( tmpss, "select from local_exchange %s Err", _LNet );
PTrace( SQLDEBUG, tmpss );
return ( -1);
}
j = sqlca.sqlerrd[2];
if ( !j )
{
sprintf( tmpss, "select from local_exchange %s is Null", _LNet );
PTrace( SQLDEBUG, tmpss );
return ( -1);
}
strcpy( Net2Exch.Local_Code, _lnet );
Net2Exch.Exch_Num = j;
for ( i = 0;i < j;i++ )
{
Net2Exch.Switch_ID[i] = _EId[i];
DeleteSpace( _ecode[i] );
strcpy( Net2Exch.Exchange_Code[i], _ecode[i] );
DeleteSpace( _XDir[i] );
l = strlen( _XDir[i] );
if ( _XDir[i][l - 1] != '/' )
{
_XDir[i][l] = '/';
_XDir[i][l + 1] = 0;
}
strcpy( Net2Exch.Exch_Dir[i], _XDir[i] );
}
return (0);
}
int Insert_Complete_Info( char *dir, char *fname, char *ecode )
{
int i;
EXEC SQL BEGIN DECLARE SECTION;
char _Dir[80], _ECode[20], _Time[20], _FLag, _FName[200];
EXEC SQL END DECLARE SECTION;
strcpy( _Dir, dir );
strcpy( _FName, fname );
strcpy( _ECode, ecode );
GetTime(0);
sprintf( _Time, "%s%s", opdate, optime );
_FLag = 'W';
EXEC SQL INSERT INTO COMPLETE_INFO( FILENAME, COMPLETE_DIR, EXCHANGE_CODE, COMPLETE_TIME, COMPLETE_FLAG )
VALUES ( : _FName, : _Dir, : _ECode,: _Time, : _FLag );
if ( sqlca.sqlcode )
{
sprintf( tmpss, "Insert complete_info %s,%s,%s err!", fname, dir, ecode );
PTrace( SQLDEBUG, tmpss );
return ( -1);
}
return (0);
}
int Search_InPut_Tab( char *_ecode, int _nn )
{
char f1[800], f2[800];
EXEC SQL BEGIN DECLARE SECTION;
char _INTName[80], _ECode[20], _FLag, _FLag1, _FName[200];
VARCHAR dynstmt[800];
EXEC SQL END DECLARE SECTION;
strcpy( _INTName, IN_TName );
strcpy( _ECode, _ecode );
_FLag = 'W';
_FLag1 = 'Y';
sprintf( f1, "SELECT FILENAME FROM %s WHERE ", _INTName );
strcpy( f2, "EXCHANGE_CODE=:v1 AND DEAL_FLAG = :v2 AND VALID_FLAG = :v3" );
sprintf( (char *)dynstmt.arr, "%s %s", f1, f2 );
dynstmt.len = (unsigned short)strlen((char *)dynstmt.arr);
EXEC SQL PREPARE SEARCH_TAB FROM :dynstmt;
if ( sqlca.sqlcode )
{
sprintf( tmpss, "prepare %s err!", (char *)dynstmt.arr );
PTrace( SQLDEBUG, tmpss );
return ( -1);
}
EXEC SQL DECLARE INPUT_CUR CURSOR FOR SEARCH_TAB;
if ( sqlca.sqlcode )
{
sprintf( tmpss, "declare %s err!", (char *)dynstmt.arr );
PTrace( SQLDEBUG, tmpss );
return ( -2);
}
EXEC SQL OPEN INPUT_CUR USING :_ECode, :_FLag, :_FLag1;
if ( sqlca.sqlcode )
{
sprintf( tmpss, "open %s err!", (char *)dynstmt.arr );
PTrace( SQLDEBUG, tmpss );
return ( -3);
}
while ( 1 )
{
EXEC SQL FETCH INPUT_CUR INTO :_FName;
if ( sqlca.sqlcode == 1403 )
break;
else if ( sqlca.sqlcode )
{
sprintf( tmpss, "fetch %s err!", (char *)dynstmt.arr );
PTrace( SQLDEBUG, tmpss );
return ( -4);
}
DeleteSpace( _FName );
sprintf( tmpss, "Deal File %s Now ...", _FName );
PTrace( TIMEDEBUG, tmpss );
if ( Deal_File( _FName, _nn ) )
{
sprintf( tmpss, "Deal File %s Err!", _FName );
PTrace( TIMEDEBUG, tmpss );
return ( -5);
}
if ( Update_InPut_Schedule( _FName ) )
{
sprintf( tmpss, "Update Schedule %s Err!", _FName );
PTrace( TIMEDEBUG, tmpss );
Rollback_Work();
return ( -6);
}
if ( Insert_OutPut_Schedule( _FName ) )
{
sprintf( tmpss, "Insert Schedule %s Err!", _FName );
PTrace( TIMEDEBUG, tmpss );
Rollback_Work();
return ( -7);
}
sprintf( f1, "%s%s%s", Net2Exch.Exch_Dir[_nn], IN_MDir, _FName );
if ( Commit_Work() )
{
Rollback_Work();
return ( -8);
}
if ( unlink( f1 ) )
{
sprintf( tmpss, "Unlink file %s Err!", f1 );
PTrace( ERRDEBUG, tmpss );
return ( -9);
}
sprintf( tmpss, "Deal File %s End !!!", _FName );
PTrace( TIMEDEBUG, tmpss );
}
EXEC SQL CLOSE INPUT_CUR;
sprintf( tmpss, "Search End" );
PTrace( TIMEDEBUG, tmpss );
if ( Commit_Work() )
{
Rollback_Work();
return ( -10);
}
return (0);
}
int Update_InPut_Schedule( char *fname )
{
char s1[800], s2[800];
EXEC SQL BEGIN DECLARE SECTION;
int _TCount, _MCount, _ECount, _OCount;
char _FName[200], _DFlag, _TName[80], _DTime[80];
VARCHAR dynstmt[800];
EXEC SQL END DECLARE SECTION;
strcpy( _TName, IN_TName );
strcpy( _FName, fname );
_DFlag = 'Y';
GetTime(0);
sprintf( _DTime, "%s%s", opdate, optime );
_TCount = FileLen;
_MCount = FileLen;
_ECount = 0;
_OCount = 0;
strcpy( s1, "DEAL_FLAG=:v1,DEAL_TIME=:v2,TOTAL_COUNT=:v3," );
strcat( s1, "MAINFLOW_COUNT=:v4,ERROR_COUNT=:v5,OTHER_COUNT=:v6 " );
strcat( s1, "WHERE FILENAME = :v7" );
sprintf( (char *)dynstmt.arr, "UPDATE %s SET %s", _TName, s1, s2 );
dynstmt.len = (unsigned short)strlen((char *)dynstmt.arr);
EXEC SQL PREPARE UPDATE_TAB FROM :dynstmt;
if ( sqlca.sqlcode )
{
sprintf( tmpss, "Prepare from %s Err!", (char *)dynstmt.arr );
PTrace( SQLDEBUG, tmpss );
return (sqlca.sqlcode);
}
EXEC SQL EXECUTE UPDATE_TAB USING :_DFlag, :_DTime, : _TCount,:_MCount, :_ECount, :_OCount, : _FName;
if ( sqlca.sqlcode )
{
sprintf( tmpss, "Update Scheudule %s,", _FName );
PTrace( SQLDEBUG, tmpss );
return (sqlca.sqlcode);
}
return (0);
}
int Insert_OutPut_Schedule( char *fname )
{
char s1[800], s2[800];
EXEC SQL BEGIN DECLARE SECTION;
int _Count;
char _FName[200], _LNet[80], _VFlag, _DFlag, _TName[80], _DTime[80];
VARCHAR dynstmt[800];
EXEC SQL END DECLARE SECTION;
strcpy( _TName, OUT_TName );
strcpy( _FName, fname );
strcpy( _LNet, fname + 2 );
_LNet[5] = 0;
_DFlag = 'W';
_VFlag = 'Y';
GetTime(0);
sprintf( _DTime, "%s%s", opdate, optime );
_Count = 0;
strcpy( s1, "FILENAME,EXCHANGE_CODE,DEAL_FLAG,DEAL_TIME,TOTAL_COUNT," );
strcat( s1, "MAINFLOW_COUNT,ERROR_COUNT,OTHER_COUNT,VALID_FLAG" );
strcpy( s2, ":v1,:v2,:v3,:v4,:v5,:v6,:v7,:v8,:v9" );
sprintf( (char *)dynstmt.arr, "INSERT INTO %s (%s) VALUES (%s)",
_TName, s1, s2 );
dynstmt.len = (unsigned short)strlen((char *)dynstmt.arr);
EXEC SQL PREPARE INSERT_TAB FROM :dynstmt;
if ( sqlca.sqlcode )
{
sprintf( tmpss, "Prepare from %s Err!", (char *)dynstmt.arr );
PTrace( SQLDEBUG, tmpss );
return (sqlca.sqlcode);
}
EXEC SQL EXECUTE INSERT_TAB USING :_FName, :_LNet, :_DFlag, :_DTime,:_Count, :_Count, :_Count, :_Count, :_VFlag;
if ( sqlca.sqlcode )
{
sprintf( tmpss, "Insert Scheudule %s,%s,%s", _FName, _LNet, _DTime );
PTrace( SQLDEBUG, tmpss );
return (sqlca.sqlcode);
}
return (0);
}
int Commit_Work()
{
EXEC SQL COMMIT WORK;
if ( sqlca.sqlcode )
{
sprintf( tmpss, "Commit Work Err!" );
PTrace( SQLDEBUG, tmpss );
return ( -1);
}
return (0);
}
int Rollback_Work()
{
EXEC SQL ROLLBACK;
return (0);
}
int PTrace( int flag, char *buf )
{
int i;
char tt[80];
GetTime(0);
sprintf( tt, "%s-%s", opdate, optime );
if ( flag == ERRDEBUG )
{
GetTime(0);
fprintf( ffp, "********** %s(%d) **********\n", tt, getpid() );
fprintf( ffp, "%s,errno=%d=\n\n", buf, errno );
}
else if ( flag == TIMEDEBUG )
{
GetTime(0);
fprintf( ffp, "********** %s(%d) **********\n", tt, getpid() );
fprintf( ffp, "%s\n\n", buf );
}
else if ( flag == SQLDEBUG )
{
fprintf( ffp, "********** %s(%d) **********\n", tt, getpid() );
fprintf( ffp, "%s : %d\n", buf, sqlca.sqlcode );
fprintf( ffp, "ORACLE error detected: %s\n", sqlca.sqlerrm.sqlerrmc );
fprintf( ffp, "Last SQL statement:%s\n", oraca.orastxt.orastxtc );
fprintf( ffp, "... at or near line number: %d\n", oraca.oraslnr );
fprintf( ffp, "****************************\n\n" );
}
else if ( flag == CHKERRDEBUG )
{
fprintf( ffp, "********** %s(%d) **********\n", tt, getpid() );
if ( sqlca.sqlcode )
{
fprintf( ffp, "%s Error!!! : %d\n", buf, sqlca.sqlcode );
fprintf( ffp, "ORACLE Error: %s\n", sqlca.sqlerrm.sqlerrmc );
fprintf( ffp, "****************************\n\n" );
fflush(ffp);
return (sqlca.sqlcode);
}
fprintf( ffp, "%s Success\n\n", buf );
}
else
fprintf( ffp, "%s\n", buf );
fflush(ffp);
return (0);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -