Re: Dynamic SQL SELECT Statements and text blobs using ESQL/C and OnLine 4.10
Posted in 1992
>From: uunet!esd.dl.nec.com!forney (Elizabeth (Liz) J. Forney) >Subject: Re: Dynamic SQL and text blobs using ESQL/C >Date: 6 Aug 92 21:23:47 GMT >X-Informix-List-Id: <news.1629> > > I am still having trouble > with setting up the the proper place to point the sqldata structure > member to in the locator structure. I am receiving "illegal ESQLC > locator errors" when trying to point the sqldata structure member to the > loc_buffer structure member. How do you set up the initialization of > the locator structure properly? The sqldata member should point to the loc_t, as I said, not the loc_buffer. Given: CREATE TABLE Blob_table (Blob_id SERIAL NOT NULL, Blob BYTE IN TABLE); And: #define sqlvar_struct sqlva And: typedef struct sqlva Sqlva; And: typedef struct sqlda Sqlda; And: typedef loc_t Blob; And: Sqlda *sqlda; And: Sqlva *sqlva; And: Blob *blob; And: PREPARE s_select FROM "SELECT Blob FROM Blob_table WHERE Blob_id = ?"; And: DESCRIBE s_select INTO :sqlda; sqlva = sqlda->sqlvar[0]; sqlva->sqldata = (char*)malloc(sizeof(loc_t)); if (sqlva->sqldata == (char *)0) error("out of memory"); blob = (Blob *)sqlva->sqldata; blob->loc_type = SQLBYTES; blob->loc_loctype = LOCMEMORY; blob->loc_buffer = (char *)0; blob->loc_bufsize = -1; blob->loc_mflags = LOC_ALLOC; blob->loc_oflags = 0; This sets up the descriptor for a blob located in memory. The system will allocate the memory for the blob when it is used to fetch the data. If you were using this to write data, you would need to worry about allocating the memory yourself. You would also have to set blob->loc_size and blob->loc_indicator. I'm not certain whether setting blob-0>loc_mflags is necessary -- it is documented as an internal item and maybe it shouldn't be set; it has done no harm and I don't investigate its value after setting it. Read the manual to see what to do for a blob in a file -- this should be a great big push in the right direction. I haven't compiled the above, nor have I got as succinct an example as this on this machine (it's on a machine at another company altogether), so it is written on the fly, not hacked from working code. But I think it's OK. Yours, Jonathan Leffler (johnl@obelix.informix.com) #include <disclaimer.h>