三十年前编写MIS中的一段程序,把前端设备中的数据收集上来,然后汇总传给后台Oracle,同时把后台变动数据从Oracle提出传进前端设备。当时前端还不是PC,需要通过串口通讯。
C
#include <stdlib.h>
#include <stdio.h>
#include <process.h>
#include <string.h>
#include <dos.h>
EXEC SQL BEGIN DECLARE SECTION; /* SQL变量定义*/
VARCHAR uid[80]; /* 用户名 */
VARCHAR pwd[20]; /* 口令 */
VARCHAR date[9];
EXEC SQL END DECLARE SECTION;
EXEC SQL INCLUDE SQLCA; /* SQL通讯区 */
char input_file_name[20],line_buffer[80];
short int ma19busy()
{
FILE *par_file;
int i;
char ch[17];
EXEC SQL BEGIN DECLARE SECTION; /* SQL变量定义*/
VARCHAR ecrno[2];
EXEC SQL END DECLARE SECTION;
EXEC SQL WHENEVER SQLERROR GOTO err;
EXEC SQL DECLARE cu CURSOR
FOR SELECT ecrno
FROM tci_ecr
WHERE ztbz='*';
EXEC SQL OPEN cu;
EXEC SQL WHENEVER NOT FOUND GOTO EXITloop;
strcpy(ch,"");
while(1)
{
EXEC SQL FETCH cu INTO :ecrno;
ecrno.arr[ecrno.len]='\0';
i=atoi(ecrno.arr);
itoa(i,ecrno.arr,10);
strcat(ch,ecrno.arr);
strcat(ch,",");
}
EXITloop:
EXEC SQL CLOSE cu;
par_file=fopen("para0410.dat","w");
fputs("#BEGIN\n",par_file);
fputs("#COMMAND = 0410\n",par_file);
fputs("#TERMINAL_ID = ",par_file);
ch[strlen(ch)-1]='\0';
fputs(ch,par_file);
fputs("\n",par_file);
fputs("#OUTPUT_FILE=ADD_U.DAT,MAIN_U.DAT,LINK_U\n",par_file);
fputs("#LOG_FILE=LOGFILE.DAT\n",par_file);
fputs("#DISP_LINE = 25\n",par_file);
fputs("#APL_RETRY = 100\n",par_file);
fputs("#END\n",par_file);
fclose(par_file);
puts(" \n");
goto end;
err:
puts("ma19busy() function");
printf("%.70s\n",sqlca.sqlerrm.sqlerrmc);
end:
return(i);
}
short plu_zt()
{
char PL[3];
int i,k;
long l;
char c[14];
EXEC SQL BEGIN DECLARE SECTION; /* SQL变量定义*/
VARCHAR spbm[14],spmc[21],gzbm[3],plums[17],pluno[14],ljplu[14],xglx[2];
float lsdj;
EXEC SQL END DECLARE SECTION;
l=atol(line_buffer);
ltoa(l,pluno.arr,10);
k=strlen(pluno.arr);
strcpy(c,"");
for(i=1;i<=13-k;i++) strcat(c,"0");
strcat(c,pluno.arr);
strcpy(pluno.arr,c);
pluno.len=strlen(pluno.arr);
for(i=15;i<=30;i++)
plums.arr[i-15]=line_buffer[i];
plums.arr[16]='\0';
plums.len=strlen(plums.arr);
switch (line_buffer[35])
{
case 'A':i=10*16;break;
case 'B':i=11*16;break;
case 'C':i=12*16;break;
case 'D':i=13*16;break;
case 'E':i=14*16;break;
case 'F':i=15*16;break;
default :PL[0]=line_buffer[35];PL[1]='\0';i=atoi(PL)*16;
}
switch (line_buffer[36])
{
case 'A':i+=10;break;
case 'B':i+=11;break;
case 'C':i+=12;break;
case 'D':i+=13;break;
case 'E':i+=14;break;
case 'F':i+=15;break;
default :PL[0]=line_buffer[36];PL[1]='\0';i+=atoi(PL);
}
itoa(i,ljplu.arr,10);
ljplu.len=strlen(ljplu.arr);
if(line_buffer[41]=='4') strcpy(xglx.arr,"2");
else if(line_buffer[42]=='2') strcpy(xglx.arr,"1");
else strcpy(xglx.arr,"0");
xglx.len=strlen(xglx.arr);
lsdj=atof(line_buffer+44)/100;
EXEC SQL WHENEVER SQLERROR CONTINUE;
EXEC SQL WHENEVER NOT FOUND CONTINUE;
strcpy(spbm.arr,"");
spbm.len=strlen(spbm.arr);
strcpy(spmc.arr,"");
spmc.len=strlen(spmc.arr);
strcpy(gzbm.arr,"");
gzbm.len=strlen(gzbm.arr);
EXEC SQL SELECT spbm,spmc,gzbm INTO :spbm,:spmc,:gzbm
FROM tci_plub WHERE pluno=:pluno AND xglx=:xglx;
spbm.arr[spbm.len]='\0';
spmc.arr[spmc.len]='\0';
gzbm.arr[gzbm.len]='\0';
EXEC SQL INSERT INTO tci_ztb(spbm,spmc,gzbm,pluno,lsdj,ljplu,xglx,plums,rq)
VALUES(:spbm,:spmc,:gzbm,:pluno,:lsdj,:ljplu,:xglx,:plums,:date);
goto end;
err:
printf("%.70s\n",sqlca.sqlerrm.sqlerrmc);
end:
return(0);
}
void main(int argc,char *argv[])
{
short int i;
char *cc;
struct dosdate_t rq;
FILE *input_file;
if(argc!=3)
{
puts("usage: in_ora user_name password ");
exit(1);
}
strcpy(uid.arr,argv[1]);
uid.len = strlen(uid.arr);
strcpy(pwd.arr,argv[2]);
pwd.len = strlen(pwd.arr);
EXEC SQL WHENEVER SQLERROR GOTO errexit; /* 出错检测 */
EXEC SQL CONNECT :uid IDENTIFIED BY :pwd; /* ORACLE登录 */
i=ma19busy();
if(i) exit;
i=spawnl(P_WAIT,"ma19drv.exe","ma19drv.exe","para0410.dat",NULL);
if(i==147)
i=spawnl(P_WAIT,"ma19drv.exe","ma19drv.exe","para0410.dat",NULL);
if(i==129)
{
puts("参数文件没有找到!");
exit;
}
else if(i==147)
{
puts("发送错!");
exit;
}
puts("发送完成! \n");
strcpy(input_file_name,"MAIN_U.DAT");
input_file=fopen(input_file_name,"r");
if(!input_file)
{
puts("没有数据文件!!"); exit(1);
}
puts("请等待...");
EXEC SQL WHENEVER NOT FOUND CONTINUE;
EXEC SQL DELETE FROM tci_ztb;
_dos_getdate(&rq);
itoa(rq.year,date.arr,10);
itoa(rq.month,cc,10);
strcat(date.arr,cc);
itoa(rq.day,cc,10);
strcat(date.arr,cc);
date.len=strlen(date.arr);
while( fgets(line_buffer,80,input_file)!=NULL ) /* 读一行 */
{
plu_zt();
fgets(line_buffer,80,input_file);
}
EXEC SQL COMMIT WORK RELEASE; /* 提交并释放资源 */
puts("OK");
exit(0);
errexit:
puts("ORACLE DATEBASE ERROR");
printf("%.70s\n",sqlca.sqlerrm.sqlerrmc);
EXEC SQL WHENEVER SQLERROR STOP; /* 出错检测 */
EXEC SQL ROLLBACK WORK RELEASE; /* 放弃并释放资源 */
exit(1);
}
#C程序# #程序猿# #程序猿糟心事#
版权声明:本文转载于今日头条,版权归作者所有,如果侵权,请联系本站编辑删除
本文采摘于网络,不代表本站立场,转载联系作者并注明出处:https://www.iotsj.com//chanye/jiguang/8147.html