⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 zjywload.ec

📁 将数据从文本文件中按照规定格式装入INFORMIX数据库中
💻 EC
字号:
#include <stdio.h>#include <signal.h>#include <string.h>#include <stdlib.h>#include <time.h>#include <unistd.h>#include <sys/types.h>EXEC SQL include sqlca;main(){  char        buf[1024];  int         len=0,i,j;  char         str1[19];  char         str2[160];  char         HOSTname[10];  FILE        *fopen(),*plfile;  FILE        *fp_topow;  char        tmpaccount[19];  char        retbxfile[100];EXEC SQL BEGIN DECLARE SECTION;     struct up {            char       account[20];            char       acc_char[156];  } uptmp,updata;EXEC SQL END DECLARE SECTION;  //生成文件名  strcpy(HOSTname,"up");  if((plfile=fopen(HOSTname,"r"))==NULL)    { printf("打开文件[%s]失败!\n",HOSTname); exit(-1); };  EXEC SQL database tmpdb;  if(sqlca.sqlcode!=0)    { printf("打开数据库出错! code=[%d]",sqlca.sqlcode); exit(-1); };  EXEC SQL BEGIN WORK;  EXEC SQL DELETE from up;  if(sqlca.sqlcode) {     printf("delete 数据库操作错! code=[%d]",sqlca.sqlcode);      EXEC SQL ROLLBACK WORK;     exit(-1);  }  EXEC SQL COMMIT WORK;       memset(buf,0x00,sizeof(buf));  for(i=0;fgets(buf,256,plfile)!=NULL;i++)    if(i!=0)      { memset(str1,0x00,sizeof(str1));        memset(str2,0x00,sizeof(str2));        memcpy(str1,buf,19);  //金额        memcpy(str2,buf+19,155);  //户号        printf("[%s]\t",str1);         printf("[%s]\n",str2);         memset(&uptmp,0x00,sizeof(uptmp));        strcpy(uptmp.account,str1);        strcpy(uptmp.acc_char,str2);             //插入到表up中              EXEC SQL BEGIN WORK;              EXEC SQL INSERT into up values(:uptmp);                if(sqlca.sqlcode!=0)                   { printf("INSERT 出错! code=[%d]",sqlca.sqlcode);                     EXEC SQL ROLLBACK WORK;                    exit(-1); };              EXEC SQL COMMIT WORK;      };     fclose(plfile);   memset(tmpaccount,0x00,sizeof(tmpaccount));  memset(retbxfile,0x00,sizeof(retbxfile));  sprintf(retbxfile,"./zjywunload.txt");  EXEC SQL DECLARE up_acc CURSOR for select * from up                                       order by account;  EXEC SQL open up_acc;  if(sqlca.sqlcode) { printf("打开游标错! sqlcode=[%d]\n",sqlca.sqlcode); };  if((fp_topow=fopen(retbxfile,"w"))==NULL){         //打开返回保险公司文件      printf("打开文件[%s]失败!\n",retbxfile);       return(-1);  }    for(;;)   {      memset(&updata,0x00,sizeof(updata));     EXEC SQL fetch up_acc into :updata;     if(sqlca.sqlcode==100) break;     else if(sqlca.sqlcode<0){printf("数据库操作败!\n");exit(-1);}      printf("[%s]\t",tmpaccount);       printf("[%s]\n",updata.account);       if(!strcmp(tmpaccount,updata.account)){      printf("[%s]\n",updata.account);}      else      {     fprintf(fp_topow,"%-19s%-155s\n",updata.account,updata.acc_char);     strcpy(tmpaccount,updata.account);     fflush(fp_topow);     }    };  fclose(fp_topow);     EXEC SQL close up_acc;  EXEC SQL close database;}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -