Re: HELP: loading BLOBs
Posted in 1996
Billy Wheeler wrote: > > Can any kind soul e-mail me ESQL/C source to load blobs into a database? > > Table structure is (picture_name, blobject) > > I know it's not exactly difficult, but I'm feeling *insanely* lazy. > > -- > Ciao, > > Billy Two programs are attached: getblob.ec and putblob.ec. They are copied from Informix manual and modified from there. You can see I am also lazy. I did not even create a new file to capture the image. Anyway, this is just a sample, not a production program. Program getblob.ec: #include <stdio.h> #include <fcntl.h> #include <malloc.h> $include sqlca; $include locator; main() { $char lv_str[20]; $long lv_int; int fd; $loc_t lv_img; int i; int j; int rtn; /* Prepare Image */ if ((fd = open("download.tif",O_WRONLY)) < 0) { printf("Can't open download.tif\\n"); exit(-1); } $DATABASE 'input@sa2'; errcheck("open database"); lv_img.loc_loctype = LOCFILE; lv_img.loc_fd = fd; lv_img.loc_oflags = LOC_WONLY; lseek(fd,0L,0); $BEGIN WORK; $SELECT bi_image INTO :lv_img FROM ODIRMS.t_batch_image WHERE bi_batch_image_id = "U00046C0001"; errcheck("select (with BYTE)"); printf(" Byte length: %d",lv_img.loc_size); $COMMIT WORK; $CLOSE DATABASE; errcheck("close database"); return(0); } errcheck(str) char *str; { if (sqlca.sqlcode == 0) { printf(" OK: \\"%s\\"\\n",str); return(0); } printf("ERROR: \\"%s\\" No: %d\\n", str, sqlca.sqlcode); printf("ISAM ERROR: %d\\n", sqlca.sqlerrd[1]); exit(-1); } Program putblob.ec: #include <stdio.h> #include <fcntl.h> #include <malloc.h> $include sqlca; $include locator; main() { $char lv_str[20]; $long lv_int; int fd; $loc_t lv_img; int i; int j; int rtn; /* Prepare Image */ if ((fd = open("upload.tif",O_RDONLY)) < 0) { printf("Can't open upload.tif\\n"); exit(-1); } $DATABASE 'frodis@frodis'; errcheck("open database"); lv_img.loc_loctype = LOCFILE; lv_img.loc_fd = fd; lv_img.loc_oflags = LOC_RONLY; lv_img.loc_size = lseek(fd,0L,2); lseek(fd,0L,0); $BEGIN WORK; $INSERT INTO frodis.t_template values (8,"tplt2301",$lv_img); errcheck("insert (with BYTE)"); $COMMIT WORK; $CLOSE DATABASE; errcheck("close database"); return(0); } errcheck(str) char *str; { if (sqlca.sqlcode == 0) { printf(" OK: \\"%s\\"\\n",str); return(0); } printf("ERROR: \\"%s\\" No: %d\\n", str, sqlca.sqlcode); printf("ISAM ERROR: %d\\n", sqlca.sqlerrd[1]); exit(-1); }