Re: multiple databases
Posted in 1991
Topics: Migration, Import/Export & Data Conversion
>Does anyone of a utility or program that will allow you to >select specific records from a database table and update a >second database with those records did you consider just generating isql statements as below? this is a bit kludgy but it works if you are under the gun. hope it helps. -------------------------------------------------------------------------------- #include <stdio.h> char strng[256]; char dbin[14]; /* database where rows are extracted from */ char dbout[14]; /* database where rows are replaced */ char tblin[14]; /* table where rows are extracted from */ char tblout[14]; /* table where rows are replaced */ char where[255]; /* where clause for selcting records */ /* statement to unload records from input table */ char isql_stmt[256] = "isql <<!\\ndatabase %s;\\nunload to /tmp/unld.%d select * from %s\\nwhere %s;\\n!\\n"; /* statement to delete records from output table */ char del_stmt[256] = "isql <<!\\ndatabase %s;\\ndelete from %s\\nwhere %s;\\n!\\n"; /* statement to replace records in output table */ char ins_stmt[256] = "isql <<!\\ndatabase %s;\\nload from /tmp/unld.%d insert into %s;\\n!\\n"; int pid,ret; FILE *inptr; /* Now start main program */ main(argc,argv) int argc; char *argv[]; { if(argc == 2) { inptr = fopen(argv[1],"r"); if(inptr == NULL) { printf("could not open parm file %s\\n",argv[1]); return; } } else return; while(fgets(strng,255,inptr)) { strng[strlen(strng)-1] = 0; if(!strncmp(strng,"dbin",4)) strcpy(dbin,&strng[5]); else if(!strncmp(strng,"dbout",5)) strcpy(dbout,&strng[6]); else if(!strncmp(strng,"tabin",5)) strcpy(tblin,&strng[6]); else if(!strncmp(strng,"tabout",6)) strcpy(tblout,&strng[7]); else if(!strncmp(strng,"where",5)) strcpy(where,&strng[6]); } close(inptr); pid = getpid(); sprintf(strng,isql_stmt,dbin,pid,tblin,where); printf("%s\\n",strng); ret = system(strng); sprintf(strng,del_stmt,dbout,tblout,where); printf("%s\\n",strng); ret = system(strng); sprintf(strng,ins_stmt,dbout,pid,tblout); printf("%s\\n",strng); ret = system(strng); } _________________________________________________________________ below is an example of the kind of parameter file you could use i tested this and it worked fine dbin=acct dbout=acct2 tabin=acct tabout=acct where=branch = " d238" or branch = " d252" ------------------------------------------------------------------------ Disclaimer: these are my own opinions and do not reflect the opinions of anyone else.