📄 复件 subnew.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][50];
char chartelecount;
int telecount;
EXEC SQL end declare section;
#include <stdio.h>
#include <sybfront.h>
#include <sybdb.h>
#include <memory.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;
char cmdbuf[BUFLEN];
char aaa[4],str[4],stri[10];
int kk,k;
long int upsubok,upsuberr,insubok,insuberr,illsub;
FILE *fout;
DBINT substatus,newservice,subpriority;
RETCODE return_code;
/* Forward declarations of the error handler and message handler routines. */
int err_handler();
int msg_handler();
void informix();
void fqquit(int i);
main(argc,argv)
int argc;
char *argv[];
{
time_t ttt;
upsubok=upsuberr=insubok=insuberr=illsub=0L;
/* 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/sub.log","a+");
time(&ttt);
fprintf(fout,"\n %s Process subcard!\n",ctime(&ttt));
fflush(fout);
EXEC SQL connect to 'yl97';
if (sqlca.sqlcode<0)
{
fprintf(fout,"Can not login to INFORMIX ,Please check!\n");
fflush(fout);
exit(-1);
}
select_informix();
fqquit(1);
dbexit();
/*EXEC SQL commit work;*/
EXEC SQL close line_cursor;
EXEC SQL disconnect current;
}
void fqquit(int i)
{
time_t ttt;
time(&ttt);
/*
fprintf(fout,"Illgile subcard =%d\n",illsub);
fprintf(fout,"Insert subcard ok =%d\n",insubok);
fprintf(fout,"Insert subcard fail =%d\n",insuberr);
fprintf(fout,"Update subcard ok =%d\n",upsubok);
fprintf(fout,"Update subcard fail =%d\n",upsuberr);
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,subname,subaddr,subpriority,subclass,linetype,howpay,newservice,termtype,termcheck,installoper,installdate,old_tel,substatus,substr(s_time,3,8) 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[14],:str1[15],:str1[17] from subscribercard where getbz='0';
EXEC SQL OPEN line_cursor;
for(i=0;i<50;i++)
{
/*EXEC SQL begin work;*/
EXEC SQL fetch line_cursor;
if (sqlca.sqlcode!=0)
{
/*EXEC SQL commit rollback;*/
printf("The database error is occured!\n");
break;
/*continue;*/
}
else
printf("The linedata telephone=%s,officenum=%s,subname=%s \n",str[0],str[1],str[2]);
}
}
/********************/
int insert_sybase(strr)
char strr[40][50];
{
/*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);
illsub=illsub+1;
kk=4;
return;
}
else
{
dbbind(dbproc,1,STRINGBIND,(DBCHAR)0,aaa);
while(dbnextrow(dbproc)!=NO_MORE_ROWS)
{
strcpy(str1[1],aaa);
}
}
}
}
/****pppp*****/
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);
*/
}
/************/
dbconvert((DBPROCESS*)NULL,SYBCHAR,str1[4],-1,SYBINT4,&subpriority,-1);
dbconvert((DBPROCESS*)NULL,SYBCHAR,str1[15],-1,SYBINT4,&substatus,-1);
dbconvert((DBPROCESS*)NULL,SYBCHAR,str1[8],-1, SYBINT4,&newservice,-1);
if ((substatus==1)&&(strncmp(str1[14]," ",4)>0))
{
substatus=0;
}
if ((strncmp(str1[14]," ",4)>0)&&(substatus==0))
{
dbfcmd(dbproc,"update SubscriberCard set SubStatus=1,Remark='Gaihao to %.7s,%.8s' where TelePhone='%.7s'",str1[0],str1[17],str1[14]);
dbsqlexec(dbproc);
}
if ((strncmp(str1[14]," ",4)>0)&&(substatus==8))
{
substatus=0;
dbfcmd(dbproc,"update SubscriberCard set SubStatus=8,Remark='YiJi to %.7s,%.8s' where TelePhone='%.7s'",str1[0],str1[17],str1[14]);
dbsqlexec(dbproc);
}
if ((strncmp(str1[14]," ",4)>0)&&(substatus==64))
{
substatus=0;
dbfcmd(dbproc,"update SubscriberCard set SubStatus=64,Remark='GeJie to %.7s,%.8s' where TelePhone='%.7s'",str1[0],str1[17],str1[14]);
dbsqlexec(dbproc);
}
/************/
if (strncmp(stri," ",4)>0)
{
/*************/
dbfcmd(dbproc,"update SubscriberCard set OfficeNum='%s',SubName='%s',SubAddress='%s',SubPriority=%d,SubClass='%s',LineType='%s',HowPay='%s',NewService=%d,TermType='%s',TermCheck='%s',InstallOper='%s',InstallDate='%s',SubStatus=%d,Remark=' ',ModifyDate=getdate() where TelePhone='%.7s'",str1[1],str1[2],str1[3],subpriority,str1[5],str1[6],str1[7],newservice,str1[9],str1[10],str1[11],str1[12],substatus,stri);
dbsqlexec(dbproc);
while ((return_code = dbresults(dbproc)) != NO_MORE_RESULTS)
{
if (return_code == FAIL)
{
fprintf(fout,"update subcard error telephone=%s\n",str1[1]);
fflush(fout);
upsuberr=upsuberr+1;
}
else
upsubok=upsubok+1;
}
/*************/
}
else
{
/***************/
dbfcmd(dbproc,"insert into SubscriberCard (TelePhone,OfficeNum,SubName,SubAddress,SubPriority,SubClass,LineType,HowPay,NewService,TermType,TermCheck,InstallOper,InstallDate,SubStatus,ModifyDate)");
dbfcmd(dbproc," values ('%s','%s','%s','%s',%d,'%s','%s','%s',%d,'%s','%s','%s','%s',%d,getdate())",str1[0],str1[1],str1[2],str1[3],subpriority,str1[5],str1[6],str1[7],newservice,str1[9],str1[10],str1[11],str1[12],substatus);
dbsqlexec(dbproc);
while ((return_code = dbresults(dbproc)) != NO_MORE_RESULTS)
{
if (return_code == FAIL)
{
fprintf(fout,"insert subcard error telephone=%s\n",str1[1]);
fflush(fout);
insuberr=insuberr+1;
}
else
insubok=insubok+1;
}
}
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 + -