Blob Information with 7.3
Posted in 1999
Topics: Stored Procedures & SPL, Connectivity: ESQL/C, 4GL & Embedded SQL, Server Administration, Data Types & Schema Design, Migration, Import/Export & Data Conversion
Anyone,
I'm trying to find out some information about byte blob data.
In the end I would like to use ESQL to access the blobinfo structure.
However, for now I just trying to make sure that column of blob data has
been
populated.
An outline of some of my steps are as follows.
1.) Created the table 'firsttry' with the following settings.
INFO - firsttry: Columns Indexes Privileges References Status ...
Display column names and data types for a table.
----------------------- bofa2@bofa2 ------------ Press CTRL-W for Help
--------
Column name Type Nulls
docid char(12) yes
acctnum char(16) yes
empty char(20) yes
date char(11) yes
image byte yes
2.) I populated the table with a text file created with an "unload"
command which looked like...
000001034041|4328030100388176||11/30/1995:|f94e26c0138f58f227c1f34128c52f114f511257ed73584a0e93225e33d5e76e04ea34a97c6409efa76a2a613aa771701ff9cb7e0001011d|
and performed a "LOAD FROM <path name to existing informix unload file>
INSERT INTO firsttry
- Message stated that 20 row(s) loaded.
3.) Using dbaccess, run a sql select * on firsttry and get ...
DISPLAY: Next Restart Exit
Display next page of results.
----------------------- bofa2@bofa2 ------------ Press CTRL-W for Help
--------
docid 000001034041
acctnum 4328030100388176
empty
date 11/30/1995:
image <BYTE value>
4.) However, while still using dbaccess, and running the folling querry
Select FAMILY(image), VOLUME(image)
from firsttry
where docid = '000001034041'
I get the following error message ...
644: FAMILY(), VOLUME(), and DESCR() require BLOB column on optical
medium.
Question?
Does this mean that the image column is not populated?
Hi,
This is a small code that could be used as a template for your end requirements ....
PK.
create table test
(
col1 int,
col2 text
);
Putblob.ec:
========
Compile line : esql putblob.ec -o put
=========
#include<stdio.h>
$include sqlca;
$include locator;
$include sqltypes;
main()
{
$struct {
int col1;
loc_t cat_desc;
} cat;
char getnum[75];
char *buff = malloc(500);
$database dbname;
printf(" Enter a Catalog number :");
gets(getnum);
cat.col1 = atoi(getnum);
printf("Enter the description :\\n");
gets(buff);
cat.cat_desc.loc_buffer = buff;
cat.cat_desc.loc_loctype = LOCMEMORY;
cat.cat_desc.loc_bufsize = 500;
cat.cat_desc.loc_size = strlen(buff);
$insert into test values (:cat.col1,:cat.cat_desc);
if(SQLCODE)
printf("Error : %d\\n ISAM : %d\\n\\n",SQLCODE,sqlca.sqlerrd[1]);
else
printf("Successfull insert\\n");
free(buff);
}
William Hughes wrote:
> Anyone,
>
> I'm trying to find out some information about byte blob data.
> In the end I would like to use ESQL to access the blobinfo structure.
> However, for now I just trying to make sure that column of blob data has
> been
> populated.
>
> An outline of some of my steps are as follows.
>
> 1.) Created the table 'firsttry' with the following settings.
> INFO - firsttry: Columns Indexes Privileges References Status ...
>
> Display column names and data types for a table.
>
> ----------------------- bofa2@bofa2 ------------ Press CTRL-W for Help
> --------
>
> Column name Type Nulls
>
> docid char(12) yes
> acctnum char(16) yes
> empty char(20) yes
> date char(11) yes
> image byte yes
>
> 2.) I populated the table with a text file created with an "unload"
> command which looked like...
>
> 000001034041|4328030100388176||11/30/1995:|f94e26c0138f58f227c1f34128c52f114f511257ed73584a0e93225e33d5e76e04ea34a97c6409efa76a2a613aa771701ff9cb7e0001011d|
>
> and performed a "LOAD FROM <path name to existing informix unload file>
> INSERT INTO firsttry>
> - Message stated that 20 row(s) loaded.
>
> 3.) Using dbaccess, run a sql select * on firsttry and get ...
> DISPLAY: Next Restart Exit
> Display next page of results.
>
> ----------------------- bofa2@bofa2 ------------ Press CTRL-W for Help
> --------
>
> docid 000001034041
> acctnum 4328030100388176
> empty
> date 11/30/1995:
> image <BYTE value>
>
> 4.) However, while still using dbaccess, and running the folling querry
>
> Select FAMILY(image), VOLUME(image)
> from firsttry
> where docid = '000001034041'
>
> I get the following error message ...
>
> 644: FAMILY(), VOLUME(), and DESCR() require BLOB column on optical
> medium.>
> Question?
> Does this mean that the image column is not populated?
William Hughes wrote:
>
> Anyone,
>
> I'm trying to find out some information about byte blob data.
> In the end I would like to use ESQL to access the blobinfo structure.
> However, for now I just trying to make sure that column of blob data has
> been
> populated.
>
> An outline of some of my steps are as follows.
>
> 1.) Created the table 'firsttry' with the following settings.
> INFO - firsttry: Columns Indexes Privileges References Status ...
>
> Display column names and data types for a table.
>
> ----------------------- bofa2@bofa2 ------------ Press CTRL-W for Help
> --------
>
> Column name Type Nulls
>
> docid char(12) yes
> acctnum char(16) yes
> empty char(20) yes
> date char(11) yes
> image byte yes
>
> 2.) I populated the table with a text file created with an "unload"
> command which looked like...
>
> 000001034041|4328030100388176||11/30/1995:|f94e26c0138f58f227c1f34128c52f114f511257ed73584a0e93225e33d5e76e04ea34a97c6409efa76a2a613aa771701ff9cb7e0001011d|
>
> and performed a "LOAD FROM <path name to existing informix unload file>
> INSERT INTO firsttry>
> - Message stated that 20 row(s) loaded.
>
> 3.) Using dbaccess, run a sql select * on firsttry and get ...
> DISPLAY: Next Restart Exit
> Display next page of results.
>
> ----------------------- bofa2@bofa2 ------------ Press CTRL-W for Help
> --------
>
> docid 000001034041
> acctnum 4328030100388176
> empty
> date 11/30/1995:
> image <BYTE value>
>
> 4.) However, while still using dbaccess, and running the folling querry
>
> Select FAMILY(image), VOLUME(image)
> from firsttry
> where docid = '000001034041'
>
> I get the following error message ...
>
> 644: FAMILY(), VOLUME(), and DESCR() require BLOB column on optical
> medium.>
> Question?
> Does this mean that the image column is not populated?
No. These functions are specific to IDS Optical Server you are not
using WORM or READONLY optical for your BLOB are you? That is why
the error. Just to verify the existence of the blob try:
SELECT docid, length(image) from firsttry where docid = '000001034041';
To properly fetch BLOBs in ESQL/C you will have to prepare and describe
the statement and specify one of four methods for fetching the BLOB
column:
LOCMEMORY - Fetch into program memory (take care for HUGE images)
LOCFILE - Fetch into an open file handle
LOCFNAME - Fetch into a named file
LOCUSER - Call user provided open/read-write/close functions
LOCUSER is the fastest method and not as complicated as one might think.
See the source to myschema.ec for sample code using LOCUSER functions
to read a BLOB. There is also a clear example in the ESQL Sample
subdir.
In older versions of the engine and ESQL LOCMEMORY was slower than
using either LOCFILE or LOCFNAME and reading the file back in. I do
not know if this is still true, and may depend on the speed of your
malloc library and how you allocate the memory buffer (there are
several options), I mostly use LOCUSER now, but one should keep this in
mind and benchmark.
At any rate all methods except LOCUSER are well documented with
examples in the ESQL/C-SDK manual.
Art S. Kagel