Getting a JPEG from a BLOB field in DB2 with Extenders

Getting a JPEG from a BLOB field in DB2 with Extenders

Post by Jerr » Thu, 21 Mar 2002 03:10:24



  > We have a db2 with the extenders that stores tiff images as blob
  > fields. Insertion works fine. Now we try to extract an image (jpeg)
  > from the database.
  > We cannot get the whole blob with a SELECT it requires 2GB in memory!
  > So, what we want to do is to grab a part of the blob as big as
  > MMDBSYS.Size(Image), which is only 2MB. This can be done with
  > Content--(--handle--,--offset--,--size--). We also want to receive the
  > images in JPEG format with some conversion. This can be done with
  > Content--(--handle--,--target_format--,--conversion_options--)
  > There is no function that fulfills both requests.
  > Any ideas how we can achieve this?
  > Thanks in advance
  > Dimitris Glezos
  > High Performance Computing Laboratory University of Patras, Greece
  > http://www.hpclab.ceid.upatras.gr/http://www.hpclab.ceid.upatras.gr

Hi, Actually, I'm trying to do the same using PHP (I have DB2 v7.2 FP5
and DB2 Image Extenders) But I'm not sure images are stored correctly in
the database and what I retrieved from the database isn't consistent...
Could you tell me how you managed to store the images as BLOB in the DB2
Database ?

Thanks

Jerry

--
Posted via dBforums
http://dbforums.com

 
 
 

Getting a JPEG from a BLOB field in DB2 with Extenders

Post by Knut Stol » Thu, 21 Mar 2002 06:09:25




>  > We have a db2 with the extenders that stores tiff images as blob
>  > fields. Insertion works fine. Now we try to extract an image (jpeg)
>  > from the database.
>  > We cannot get the whole blob with a SELECT it requires 2GB in memory!

What's the error message?

It is not correct that db2 returns you a 2GB BLOB (image).  The definition
of the function means that it can deal with up to 2GB.  But if the images
are smaller, then you get less data.

Quote:>  > So, what we want to do is to grab a part of the blob as big as
>  > MMDBSYS.Size(Image), which is only 2MB.

That means you get the complete image - all of it.

Quote:>  > This can be done with
>  > Content--(--handle--,--offset--,--size--). We also want to receive the
>  > images in JPEG format with some conversion. This can be done with
>  > Content--(--handle--,--target_format--,--conversion_options--)
>  > There is no function that fulfills both requests.

Given that you want to have the complete image, the second version should
suffice.

Quote:> Hi, Actually, I'm trying to do the same using PHP (I have DB2 v7.2 FP5
> and DB2 Image Extenders) But I'm not sure images are stored correctly in
> the database and what I retrieved from the database isn't consistent...
> Could you tell me how you managed to store the images as BLOB in the DB2
> Database ?

What exactly is the problem and how did you determine the inconsistencies?

p.s: I don't know much about PHP.  Maybe the language binding for PHP thinks
that it can get a 2GB BLOB and tries to allocate that much memory.  You
should look at PHP in that case to see what should be done differently.
Maybe there is a streaming interface or some other support, maybe based on
LOCATORs?

--
Knut Stolze
DB2 Spatial Extender
IBM Silicon Valley Lab

 
 
 

Getting a JPEG from a BLOB field in DB2 with Extenders

Post by Jerr » Thu, 21 Mar 2002 21:09:06


Hi,

The first test I did was using QMF, and a server file. But infact this
is what I'm trying to do:

I'm using an HTML form to post the data with
enctype="multipart/form-data" and the INPUT type file named userfile.

Then I used the following PHP Script:

$insOS="Insert Into mytable (imgname,imgval) values('image
name',MMDBSYS.DB2IMAGE('dbname',CAST('$userfile' AS
BLOB($userfile_size)),'JPG',1,CAST(NULL AS LONG VARCHAR),'Test
Jerry'));";

$resultOSins=odbc_exec($conn,$insOS);

($conn is my connection string)

The size of the image is 3343 Bytes

Then I have the error: "Warning: SQL error: [IBM][CLI Driver][DB2/NT]
SQL0443N Routine "MMDBSYS.DB2IMAGE" (specific name "DB2IMAGEIMPORTC1")
has returned an error SQLSTATE with diagnostic text "Can't open/read
content file. ". SQLSTATE=38603 , SQL state 38603 in SQLExecDirect in
/svr/jerry/dbstoreimg.php on line 46"

Is this SQL statment not correct ? Is it a problem with Image Extender ?
Indeed looking at the tables (all tables in this database) even when I
managed to insert a server file in a table as a BLOB using QMF, I could
find a few information regarding this image like the size, format,...
but couldn't find anything looking like a BLOB. Is it normal ?

Thanks.

Jerry

--
Posted via dBforums
http://dbforums.com