Re: BLOBS
Posted in 1996
Try this skeleton code with your modifications ... I haven't compiled it, but I guess you got the idea. PS :- This should compile with version 6 of Informix engines. Can't remember when the ansi 'EXEC SQL' syntax was introduced in ESQL/C programs. The older versions only supported the Informix introduced '$'. ------------------------------------------- #include <stdio.h> #include <fcntl.h> #include <errno.h> #include <ctype.h> EXEC SQL include sqltypes; EXEC SQL include locator; #define OUTFILE "myfile.blb" long error_flag = 0; main(argc, argv) int argc; char **argv; { EXEC SQL BEGIN DECLARE SECTION; loc_t m_pic_blob; EXEC SQL END DECLARE SECTION; int fd; EXEC SQL database mydb; /* * Now fetch the blob from the table and write to a file. */ fprintf (stderr, "Now read the blob data back from the table."); if ((fd = open (OUTFILE, O_CREAT|O_WRONLY, 0644)) < 0) { fprintf(stderr, "Error opening blob output file <%s>\\n", OUTFILE); goto err_happened; } /* * Prepare the locator structure for select of picture blob. */ m_pic_blob.loc_loctype = LOCFILE; m_pic_blob.loc_fd = fd; m_pic_blob.loc_oflags = LOC_APPEND; EXEC SQL declare c1 cursor for select pic_blob from mytab; EXEC SQL open c1; while (! SQLCODE) { EXEC SQL fetch c1 into :m_pic_blob; if (SQLCODE == SQLNOTFOUND) break; } /* Deallocate file descriptors */ close (fd); EXEC SQL close c1; EXEC SQL free c1; ver_sqlcode((long)0); err_happened: /* Close the database and terminate program */ EXEC SQL close database; exit (error_flag); } -- Bobby +---------------------------------------------------------------------------+ | Informix Software Inc. 4100 Bohannon Drive, Menlo Park, California 94025 | | Telephone: +415 926-6502 Fax: +415 926-6571 E-Mail: bobbys@informix.com | +------------------------standard-disclaimers-apply-------------------------+ On 31 Mar 1996, BSMGOOSE wrote: |I am trying to extract an image "BLOB", bytes field, from an |Informix-Turbo database, and place it into a Unix flat file. I would |prefer using ESQL C. Any help would be greatly appreciated! | |