戻る

データ流し込みプロフラムの例 ( gcc / gpre )

0001: /********************************************
0002:  * ctest002.e
0003:  ********************************************/
0004: #include <stdio.h>
0005: #include <time.h>
0006: #include <stdlib.h>
0007: #include <string.h>
0008: #include <ibase.h>
0009: 
0010: double getnanosec()
0011: {
0012:     double         sec, nsec;
0013:     struct timeval tv;
0014:     gettimeofday(&tv, 0);
0015:     sec=(double)tv.tv_sec;
0016:     nsec=(double)tv.tv_usec;
0017:     return sec+nsec/1000000;
0018: }
0019: 
0020: char* parseline(char **p, char **q)
0021: {
0022:     char *pp;
0023:     *q=strchr(*p, ',');
0024:     if (*q) **q=0;
0025:     pp=*p;
0026:     *p=*q+1;
0027:     return pp;
0028: }
0029: 
0030: int main(int argc, char **argv)
0031: {
0032:     double nsec0, nsec1, nsec2;
0033:     FILE   *INFIL;
0034:     char   buff[1024];
0035:     char   *p, *q;
0036:     int    updt;
0037:     int    r1, r2, r3, r4;
0038:     int    c1, c2, c3, c4;
0039:     int    i;
0040: 
0041:     c1=c2=c3=c4=0;
0042:     
0043:     EXEC SQL SET DATABASE DB="/DB/birds/birdsX.fdb"
0044:         USER "SYSDBA" PASSWORD "********";
0045:     BASED ON ORDERTAB.SEQNO         O_seqno;
0046:     BASED ON ORDERTAB.ORDERNAME     O_ordername;
0047:     BASED ON ORDERTAB.ORDERJPN      O_orderjpn;
0048:     BASED ON FAMILY.SEQNO           F_seqno;
0049:     BASED ON FAMILY.ORDERNAME       F_ordername;
0050:     BASED ON FAMILY.FAMILYNAME      F_familyname;
0051:     BASED ON FAMILY.FAMILYJPN       F_familyjpn;
0052:     BASED ON GENUS.SEQNO            G_seqno;
0053:     BASED ON GENUS.FAMILYNAME       G_familyname;
0054:     BASED ON GENUS.GENUSNAME        G_genusname;
0055:     BASED ON GENUS.GENUSJPN         G_genusjpn;
0056:     BASED ON SPECIES.SEQNO          S_seqno;
0057:     BASED ON SPECIES.GENUSNAME      S_genusname;
0058:     BASED ON SPECIES.SPECIESNAME    S_speciesname;
0059:     BASED ON SPECIES.SPECIESJPN     S_speciesjpn;
0060:     BASED ON SPECIES.SPECIESENG     S_specieseng;
0061:     BASED ON SPECIES.SPECIESENGCAP  S_speciesengcap;
0062: 
0063:     EXEC SQL SET NAMES EUCJ_0208;
0064:     EXEC SQL CONNECT DB USER 'SYSDBA' PASSWORD '********';
0065: 
0066:     nsec0=getnanosec();
0067:     nsec1=nsec0;
0068:     if ((INFIL=fopen("/DB/birds/isql/BIRDLIST.TXT", "r"))==NULL) exit(1);
0069: 
0070:     i=0;
0071:     EXEC SQL SET TRANSACTION;
0072:     while (fgets(buff, 1024, INFIL)){
0073:         if (strncmp(buff, "//", 2)==0) continue;
0074:         i++;
0075:         if (i%1000==0){
0076:             printf("o");
0077:             fflush(stdout);
0078:         }else if (i%100==0){
0079:             printf(".");
0080:             fflush(stdout);
0081:         }
0082:         if (i%10000==0){
0083:             nsec2=getnanosec();
0084:             printf("%6d %8.3f %5d\n", i, nsec2-nsec1, i/((int)nsec2-(int)nsec1));
0085:             nsec1=nsec2;
0086:         }
0087:                 
0088:         p=strrchr(buff, '\n');
0089:         if (p) *p=0;
0090:         strcat(buff, ",");
0091:         p=buff;
0092:         strcpy(S_speciesname, parseline(&p, &q));
0093:         strcpy(S_specieseng,  parseline(&p, &q));
0094:         strcpy(S_speciesjpn,  parseline(&p, &q));
0095:         strcpy(G_genusname,   parseline(&p, &q));
0096:         strcpy(G_genusjpn,    parseline(&p, &q));
0097:         strcpy(F_familyname,  parseline(&p, &q));
0098:         strcpy(F_familyjpn,   parseline(&p, &q));
0099:         strcpy(O_ordername,   parseline(&p, &q));
0100:         strcpy(O_orderjpn,    parseline(&p, &q));
0101:         strcpy(S_speciesengcap, S_specieseng);
0102:         for (p=S_speciesengcap; *p; p++) *p=toupper(*p);
0103:         updt=0;
0104:         EXEC SQL EXECUTE PROCEDURE
0105:             PSGFO_CHKINSERT
0106:             :updt,
0107:             :O_ordername, :O_orderjpn,
0108:             :F_familyname, :F_familyjpn,
0109:             :G_genusname, :G_genusjpn,
0110:             :S_speciesname, :S_speciesjpn, :S_specieseng, :S_speciesengcap
0111:             RETURNING_VALUES
0112:             :r1, :r2, :r3, :r4;
0113:         c1+=r1;
0114:         c2+=r2;
0115:         c3+=r3;
0116:         c4+=r4;
0117:     }
0118:     EXEC SQL COMMIT;
0119:     fclose(INFIL);
0120: 
0121:     nsec2=getnanosec();
0122:     printf("%6d %8.3f %5d\n", i, nsec2-nsec1, i/((int)nsec2-(int)nsec1));
0123: 
0124:     printf("%6d%6d%6d%6d  elapsed:%8.3f\n", c1, c2, c3, c4, nsec2-nsec0);
0125:     
0126:     EXEC SQL COMMIT;
0127:     EXEC SQL DISCONNECT DB;
0128:     exit(0);
0129: }

この HTML を検査する。( XHTML 1.0 Strict で書かれています )
Another HTML Lint Gateway ( Mirrored by htmllint.oosato.org )