Re: Transferring data from flat file to existing database
Posted in 1992
> > I like to transfer the data from flat file to an existing database. I like to > know how other sites handle it? My flat file identifies whether the data > needs to be added or deleted. Is there any utility in Informix that can > read the flat file and then determine If I should add or remove? > Two methods I know of: 1: Refer Tech Notes Winter 1990 Pages 27 to 39 2: Below hacked real code into pseudo code of a 4gl program with a 'c' module: import.4gl: ------------------------------- START ----------------------------- database dbname globals define buf char(100), test_eof smallint function f_name() define prefix char(6) {to handle multiple ascci files} if not check_ascii_file() then display "FILE NOT FOUND " sleep 3 return end if let test_eof = 0 call get_line() returning test_eof, buf while test_eof = 0 case when buf[1,9] = file_id1 call imp_file1() when buf[1,9] = file_id2 call imp_file2() end case call get_line() returning test_eof, buf end while end function function imp_file1() { DO WITH "buf" WHATEVER YOU WANT TROUGH: let mem_var = buf[1,n] FURTHER CODE (add, delete ?) } end function ------------------------------- END ----------------------------- import.c ------------------------------- START ----------------------------- #include <stdio.h> #define OK 0 #define TRUE 0 #define FALSE 1 char workbuf[600]; FILE *fopen(), *fp; check_ascii_file() { if ((fp = fopen("/usr/ascii_file_name","r")) == NULL) retint (FALSE); else { retint (FALSE); } return(1); } get_line() { int c, i; int eof_test = 0; for (i = 0 ; ((c = getc(fp)) != EOF) && (c != '\\n') && (c != '\\f'); i++ ) workbuf[i] = c; workbuf[511] = '\\0'; if (c == EOF || c == '\\f') { fclose(fp); eof_test = FALSE; } retint(eof_test); retquote(workbuf); return(2); } ------------------------------- END ----------------------------- Hope this works for you, good luck -- Gert Blij +27/(0)21/933 4400 Shoprite Holdings Ltd gert@shop4.uunet.uu.net P O Box 700 ..!uunet!ddsw1!olsa99!kcms!aim1!shop4!gert Parow, 7500, South Africa