Re: esqlc - inserting BLOBS + non-BLOBS in same command
Posted in 1997
Topics: Error Codes & Troubleshooting, Connectivity: ESQL/C, 4GL & Embedded SQL, Data Types & Schema Design
On Tue, 7 Jan 1997 adil@msil.sps.mot.com wrote:
> 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
> deleted several
> lines from original
> This isn't true, is it? There is a way to insert everything in one
> shot, isn't there?
> Any suggestions?
> Thanks,
>
> Adi.
> -------------------==== Posted via Deja News ====-----------------------
> http://www.dejanews.com/ Search, Read, Post to Usenet
>
>
Adi,
The following is a heavily edited version of a routine which inserts
a record containing an int, date,blob,int into a database table
via esql/c. The code does not contain a means for setting the host
variables but does illustrate one method of inserting various data types
within a single record.
For your info the table ipscot looks like:
create table ipscot
(
co_doc_key integer not null,
co_archv_date date not null,
co_tc_image byte in ftd_tst_01, < optical storage space
co_page_nbr smallint not null
);
Application looks like
#include <stdio.h>
#include <string.h>
EXEC SQL include locator;
void Error(char *txt)
{
printf("ERROR: %s\\n",txt);
exit(1);
}
void Syntax()
{
printf("Load data into IPSCOT....\\n");
printf("loadcot <dbname> <nrows> <year>\\n");
printf(" where \\n");
printf(" dbname - database to load\\n");
printf(" nrows - number of rows to add\\n");
printf(" year - data is distributed evenly over this year\\n");
exit(0);
}
void SQERR()
{
printf("SQLC: %d\\n",sqlca.sqlcode);
printf("ISAM: %d\\n",sqlca.sqlerrd[1]);
exit(0);
}
main(int argc, char **argv)
{
EXEC SQL WHENEVER SQLERROR CALL SQERR;
EXEC SQL BEGIN DECLARE SECTION;
char bfr[1200];
char dbname[20];
int doc_key =0;
int pnbr = 1;
char tdate[]={"01/01/1996"};
char lcldate[20];
char dsc[113]; /* a blob descriptor from optical storage*/
loc_t pix; /* a locator structure */
int i,j;
int iyear;
int iter,nter,ndays,nrows,crows;
EXEC SQL END DECLARE SECTION;
if(argc != 4)Syntax();
strcpy(dbname,argv[1]);
nrows = atoi(argv[2]);
iyear = atoi(argv[3]);
EXEC SQL CONNECT TO :dbname;
...
a whole bunch of stuff deleted from here
not germane to topic at hand
...
pix.loc_loctype = LOCMEMORY;
pix.loc_size = 112;
pix.loc_buffer = dsc; /* 112 byte optical descriptor*/
pix.loc_bufsize = 112;
pix.loc_oflags |= LOC_DESCRIPTOR;
EXEC SQL insert into ipscot(co_doc_key,co_archv_date,
co_tc_image,co_page_nbr)
values(:doc_key,:lcldate,:pix,:pnbr);
EXEC SQL disconnect current; /* cleanup */
}
This will insert a single row with co_doc_key,co_archv_date,
co_tc_image and co_page_nbr into ipscot...
VALUES for doc_key,etc WOULD BE READ FROM A FILE ...
Hope this helps
J. Wysocki