Re: esqlc - inserting BLOBS + non-BLOBS in same command
Posted in 1997
>From: adil@msil.sps.mot.com >Date: Tue, 07 Jan 1997 04:01:11 -0600 >X-Informix-List-Id: <news.32298> > >I'm working with informix online 5, and I have an esqlc question: >I have a table containing some regular type fields (chars, ints, etc), >and one blob field (text). I now want to insert a new record to this >table from a c program. Idealy, I would put the data in a load file and >use the load command to get it in the database, but of course load does >not work from esqlc (or am I wrong? I'd love to be corrected on this!). No, LOAD is not a part of ESQL/C. >So now remains the use of the various esqlc commands. Unfortunately, >all the examples in the book show how to insert and access a blob by >itself, and not as one of several items to be inserted. This has the >implication that to do what I have to do, I first have to insert all >the regular data, then update that record with the blob data. >This isn't true, is it? No, it is not true. >There is a way to insert everything in one shot, isn't there? Yes, there is. Given that you have 5.0x, you have three options, depending on how flexible you need to be. The simplest (but therefore least flexible) is to create variables for the fields: EXEC SQL BEGIN DECLARE SECTION; char field1[33]; long field2; loc_t field3; EXEC SQL END DECLARE SECTION; ...Initialize variables field1, field2, field3... EXEC SQL INSERT INTO SomeTable VALUES(:field1, :field2, :field3); You would use the 1-blob-at-a-time examples to work out how to initialize the blob (field3). If you need to be more flexible, then you will either use SQLDA structures or SQL descriptors. Either way, the principle is the same. You create a locator (loc_t) structure to describe the blobs, and you include these in the correct place in the SQLDA structure or SQL descriptor. The key is to create a locator structure for each blob field, and to reference the locator structures as if they were integer variables. You could also consider poking around the IIUG archives for SQLCMD, which has code to handle loading blobs (see http://www.iiug.org). It uses SQLDA structures because it pre-dates the SQL descriptors introduced in version 5 ESQL/C. Or you could find DBD::Informix Version 0.25 on the CPAN network (see http://www.perl.org or http://www.perl.com) for code that uses SQL descriptors. I wrote most of both these chunks of code. Yours, Jonathan Leffler (johnl@informix.com) #include <disclaimer.h>