📄 linenew.ec
字号:
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <stdlib.h>
EXEC SQL begin declare section;
char telephone[10];
char officenum[15];
char str1[40][60];
int telecount=0;
char chartelecount;
EXEC SQL end declare section;
#include <stdio.h>
#include <sybfront.h>
#include <sybdb.h>
#include <time.h>
#include <sys/signal.h>
#define BUFLEN 2048
#define HEXLEN 510
#define PLEN 25
#define USER "reltec112"
#define PASSWORD "HIyou112"
#define ERR_CH stderr
LOGINREC *login;
DBPROCESS *dbproc;
long int inlineok,inlinerr,uplineok,uplinerr,illline;
FILE *fout;
char cmdbuf[BUFLEN];
char aaa[4],str[4],stri[10];
DBINT substatus,newservice,subpriority;
int kk;
RETCODE return_code;
/* Forward declarations of the error handler and message handler routines. */
int err_handler();
int msg_handler();
void fqquit(int i);
main(argc,argv)
int argc;
char *argv[];
{
time_t ttt;
inlineok=inlinerr=uplineok=uplinerr=illline=0L;
/*int i,j;*/
/* Install the user-supplied error-handling and message-handling
* routines. They are defined at the bottom of this source file.
*/
dberrhandle(err_handler);
dbmsghandle(msg_handler);
signal(SIGUSR1,fqquit);
/* Allocate and initialize the LOGINREC structure to be used
* to open a connection to SQL Server.
*/
putenv("SYBASE = /usr/sybase");
putenv("DSQUERY=C_CATS112");
putenv("DSLISTEN=SYBASE");
putenv("INFORMIXDIR=/usr/informix");
putenv("INFORMIXSERVER=online_a");
if (dbinit() == FAIL)
return(0);
login = dblogin();
DBSETLUSER(login,USER);
DBSETLPWD(login, PASSWORD);
dbproc = dbopen(login, NULL);
if (dbproc==NULL)
{
fprintf(stderr,"Can not login to SYBASE ,Please check!\n");
exit(-1);
}
dbuse(dbproc,"REL112");
fout=fopen("/usr/informix/datashare/line.log","a+");
time(&ttt);
fprintf(fout,"\n %s Process linecard!\n",ctime(&ttt));
fflush(fout);
EXEC SQL connect to 'yl97';
if (sqlca.sqlcode<0)
{
fprintf(stderr,"Can not login to INFORMIX ,Please check!\n");
exit(-1);
}
select_informix();
fqquit(1);
dbexit();
EXEC SQL close line_cursor;
EXEC SQL disconnect current;
}
void fqquit(int i)
{
time_t ttt;
time(&ttt);
fprintf(fout,"Illigle linecard = %d\n",illline);
fprintf(fout,"Insert linecard ok= %d\n",inlineok);
fprintf(fout,"Update linecard ok= %d\n",uplineok);
fprintf(fout,"Insert linecard fail= %d\n",inlinerr);
fprintf(fout,"Update linecard fail= %d\n",uplinerr);
fprintf(fout,"%s end process!\n",ctime(&ttt));
fflush(fout);
}
/********************/
select_informix()
{
int i,j;
EXEC SQL DECLARE line_cursor CURSOR FOR select TelePhone,OfficeNum,Equipment,MDFV,MDFH,Pcable1,substr(PcableP1,1,20),substr(Pcable2,1,20),substr(PcableP2,1,20),Cabinet1,Cabinet2,substr(Scable1,1,20),substr(Scable2,1,20),substr(Panel1,1,20),Panel2,Carrier1,EquipAddr1 into :str1[0],:str1[1],:str1[2],:str1[3],:str1[4],:str1[5],:str1[6],:str1[7],:str1[8],:str1[9],:str1[10],:str1[11],:str1[12],:str1[13],:str1[14],:str1[15],:str1[16] from LineCard where getbz is null;
EXEC SQL OPEN line_cursor;
for(i=0;i<50000;i++)
{
EXEC SQL fetch line_cursor;
if (sqlca.sqlcode!=0)
{
break;
/*continue;*/
}
EXEC SQL select count(*) into :telecount from LineCard where telephone=:str1[0] ;
if (sqlca.sqlcode!=0)
{
break;
}
chartelecount=telecount+48;
$update linecard set getbz=:chartelecount,e_time=current where telephone=:str1[0];
if (sqlca.sqlcode!=0)
{
break;
}
if (telecount>1)
{
$select max(s_time) into :str1[18] from linecard where telephone=:str1[0] group by telephone;
if (sqlca.sqlcode!=0)
{
printf("SQLCA.SQLCODE select max is %d\n",sqlca.sqlcode);
break;
}
$select Equipment,MDFV,MDFH,Pcable1,substr(PcableP1,1,20),substr(Pcable2,1,20),substr(PcableP2,1,20),Cabinet1,Cabinet2,substr(Scable1,1,20),substr(Scable2,1,20),substr(Panel1,1,20),Panel2,Carrier1,EquipAddr1 into :str1[2],:str1[3],:str1[4],:str1[5],:str1[6],:str1[7],:str1[8],:str1[9],:str1[10],:str1[11],:str1[12],:str1[13],:str1[14],:str1[15],:str1[16] from LineCard where telephone=:str1[0] and s_time=:str1[18];
if(sqlca.sqlcode!=0)
{
if (sqlca.sqlcode==-284)
{
$select max(rowid) into :str1[19] from linecard where telephone=:str1[0] group by telephone;
if(sqlca.sqlcode!=0)
{
break;
}
$select Equipment,MDFV,MDFH,Pcable1,substr(PcableP1,1,15),substr(Pcable2,1,15),substr(PcableP2,1,15),Cabinet1,Cabinet2,substr(Scable1,1,16),substr(Scable2,1,16),substr(Panel1,1,16),Panel2,Carrier1,EquipAddr1 into :str1[2],:str1[3],:str1[4],:str1[5],:str1[6],:str1[7],:str1[8],:str1[9],:str1[10],:str1[11],:str1[12],:str1[13],:str1[14],:str1[15],:str1[16] from LineCard where telephone=:str1[0] and rowid=:str1[19];
if(sqlca.sqlcode!=0)
{
break;
}
/*continue;*/
}
/*else
break;*/
}
}
/************/
strcpy(stri,"");
dbfcmd(dbproc,"select TelePhone from SubscriberCard where TelePhone ='%.7s'",str1[0]);
dbsqlexec(dbproc);
return_code=dbresults(dbproc);
if (return_code==FAIL)
{
return(-11);
}
dbbind(dbproc,1,STRINGBIND,(DBCHAR)0,stri);
while(dbnextrow(dbproc)!=NO_MORE_ROWS)
{
/* printf("dn=%s",stri);
*/
}
/************/
if (strcmp(stri," ")>0)
{
kk=0;
insert_sybase(str1);
if (kk==3)
return;
if(kk==4)
$update linecard set getbz='*' where telephone=:str1[0];
if (kk!=3&&kk!=4)
{
$delete from linecard where telephone=:str1[0];
if (sqlca.sqlcode!=0)
{
EXEC SQL rollback work;
break;
}
}
}
else
{
$update linecard set getbz='$',e_time=current where telephone=:str1[0];
if (sqlca.sqlcode!=0)
{
break;
}
}
}
}
/********************/
int insert_sybase(strr)
char strr[40][50];
{
/*sprintf(str,"%.4s",strr[0]);
*/
/*if (strr[0][0]=='P')
sprintf(str,"%.4s","P ");
else*/
sprintf(str,"%.4s",strr[0]);
/****pppp*****/
dbfcmd(dbproc,"select OfficeNum from Exchange where Exchange like '%.3s'",str);
if(dbsqlexec(dbproc)==FAIL)
{
fprintf(fout,"select offnum '%.3s'fail!\n",str);
fflush(fout);
kk=3;
return;
}
if((return_code=dbresults(dbproc))!=NO_MORE_RESULTS)
{
if (return_code!=FAIL)
{
if (DBROWS(dbproc)!=SUCCEED)
{
fprintf(fout,"112 has not offnum '%.3s'!\n",str);
fflush(fout);
illline=illline+1;
kk=4;
return;
}
else
{
dbbind(dbproc,1,STRINGBIND,(DBCHAR)0,aaa);
while(dbnextrow(dbproc)!=NO_MORE_ROWS)
strcpy(str1[1],aaa);
}
}
}
/****pppp*****/
strcpy(stri,"");
dbfcmd(dbproc,"select TelePhone from LineCard where TelePhone ='%.7s'",str1[0]);
dbsqlexec(dbproc);
return_code=dbresults(dbproc);
if (return_code==FAIL)
return(-11);
dbbind(dbproc,1,STRINGBIND,(DBCHAR)0,stri);
while(dbnextrow(dbproc)!=NO_MORE_ROWS)
{
/*
printf("dn=%s",stri);
*/
}
/************/
if (strcmp(stri," ")>0)
{
/*************/
dbfcmd(dbproc,"update LineCard set OfficeNum='%s',MDFV='%s',MDFH='%s',Pcable1='%s',PcableP1='%s',Pcable2='%s',PcableP2='%s',Cabinet1='%s',Cabinet2='%s',Scable1='%s',Scable2='%s',Panel1='%s',Panel2='%s', Carrier1='%s' where TelePhone='%.7s'",str1[1],str1[3],str1[4],str1[5],str1[6],str1[7],str1[8],str1[9],str1[10],str1[11],str1[12],str1[13],str1[14],str1[15],stri);
dbsqlexec(dbproc);
while ((return_code = dbresults(dbproc)) != NO_MORE_RESULTS)
{
if (return_code == FAIL)
{
fprintf(fout,"update linecard err telephone=%s\n",str1[1]);
fflush(fout);
uplinerr=uplinerr+1;
}
else
uplineok=uplineok+1;
}
dbfcmd(dbproc,"update LineCard set EquipAddr1='%s' where TelePhone='%.7s'",str1[16],stri);
dbsqlexec(dbproc);
while ((return_code = dbresults(dbproc)) != NO_MORE_RESULTS)
{
if (return_code == FAIL)
printf("One of theupdate statements FAILed.\n");
}
}
else
{
/***************/
printf("insert the database!\n");
dbfcmd(dbproc,"insert into LineCard(TelePhone,OfficeNum,MDFV,MDFH,Pcable1,PcableP1,Pcable2,PcableP2,Cabinet1,Cabinet2,Scable1,Scable2,Panel1,Panel2,Carrier1)");
dbfcmd(dbproc," values ('%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s','%s')",str1[0],str1[1],str1[3],str1[4],str1[5],str1[6],str1[7],str1[8],str1[9],str1[10],str1[11],str1[12],str1[13],str1[14],str1[15]);
dbsqlexec(dbproc);
while ((return_code = dbresults(dbproc)) != NO_MORE_RESULTS)
{
if (return_code == FAIL)
{
fprintf(fout,"insert linecard err telephone=%s\n",str1[1]);
fflush(fout);
inlinerr=inlinerr+1;
}
else
inlineok=inlineok+1;
}
dbfcmd(dbproc,"update LineCard set EquipAddr1='%s' where TelePhone='%.7s'",str1[16],stri);
dbsqlexec(dbproc);
while ((return_code = dbresults(dbproc)) != NO_MORE_RESULTS)
{
if (return_code == FAIL)
printf("One of theupdate statements FAILed.\n");
}
}
strcpy(stri,"");
return(return_code);
}
int err_handler(dbproc, severity, dberr, oserr, dberrstr, oserrstr)
DBPROCESS *dbproc;
int severity;
int dberr;
int oserr;
char *dberrstr;
char *oserrstr;
{
if ((dbproc == NULL) || (DBDEAD(dbproc)))
return(INT_EXIT);
else
{
printf("DB-Library error:\n\t%s\n", dberrstr);
if (oserr != DBNOERR)
printf("Operating-system error:\n\t%s\n", oserrstr);
return(INT_CANCEL);
}
}
int msg_handler(dbproc, msgno, msgstate, severity, msgtext,
srvname, procname, line)
DBPROCESS *dbproc;
DBINT msgno;
int msgstate;
int severity;
char *msgtext;
char *srvname;
char *procname;
DBUSMALLINT line;
{
printf ("Msg %ld, Level %d, State %d\n",
msgno, severity, msgstate);
if (strlen(srvname) > 0)
printf ("Server '%s', ", srvname);
if (strlen(procname) > 0)
printf ("Procedure '%s', ", procname);
if (line > 0)
printf ("Line %d", line);
printf("\n\t%s\n", msgtext);
return(0);
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -