Re: Loading image file on Informix on NT
Posted in 1997
>Date: Fri, 25 Apr 1997 08:54:41 -0700 >From: Amita Shrivastava <bflams@uranium.bfl.soft.net> >X-Informix-List-Id: <list.14204> > >Hi > >I have a image file on my hard disk [jpeg file]. How do I convert into a >blob data type and store it in my informix table. How do we construct the >insert statement for this. > >INFORMIX ver 7.x on WIN NT4.0 server version > >Thanks in advance It needs generalizing (and maybe de-Unixizing), but the code below shows how. The stderr.h file was part of SQLCMD which I posted last week -- in fact, so was this source file. You can remove the setarg0() and usage() calls and get on without stderr.h. Yours, Jonathan Leffler (johnl@informix.com) #include <disclaimer.h> /* @(#)File: ldblob.ec @(#)Version: 1.1 @(#)Last changed: 92/09/15 @(#)Purpose: Load a pair of blobs into test:blobs table @(#)Author: J Leffler @(#)Copyright: (C) JLSS 1992 @(#)Product: :PRODUCT: */ /*TABSTOP=4*/ #include <stdio.h> #include <sqlca.h> #include <locator.h> #include "stderr.h" #include <sqltypes.h> #define NIL(x) ((x)0) extern void sql_error(); extern void locate_file(); #ifndef lint static char sccs[] = "@(#)ldblob.ec 1.1 92/09/15"; #endif main(argc, argv) int argc; char **argv; { exec sql begin declare section; loc_t byte; loc_t text; exec sql end declare section; setarg0(argv[0]); if (argc != 3) usage("byte-blob text-blob"); locate_file(&byte, SQLBYTES, argv[1]); locate_file(&text, SQLTEXT, argv[2]); exec sql database test; if (sqlca.sqlcode != 0) sql_error("database test"); exec sql insert into blobs values (0, :text, :byte); if (sqlca.sqlcode != 0) sql_error("insert into blobs"); return(0); } void locate_file(blob, type, file) loc_t *blob; int type; char *file; { blob->loc_indicator = 0; blob->loc_type = type; blob->loc_loctype = LOCFNAME; blob->loc_fname = file; blob->loc_oflags = LOC_RONLY; blob->loc_size = -1; } /* Database generated error */ void sql_error(s) char *s; { char buffer[512]; fflush(stdout); rgetmsg(sqlca.sqlcode, buffer, sizeof(buffer)); fprintf(stderr, "SQL %d: ", sqlca.sqlcode); if (sqlca.sqlerrd[1] != 0) fprintf(stderr, "(ISAM %d) ", sqlca.sqlerrd[1]); fprintf(stderr, buffer, sqlca.sqlerrm); if (s != NIL(char *)) fprintf(stderr, "%s\\n", s); }