IBM Books

Image, Audio, and Video Extenders Administration and Programming

DB2Image


Image Audio Video
X    

Stores the content of an image in a database table. The image source can be in a client buffer, client file, or server file. The image can be stored in the database table as a BLOB, or in a server file (referred to by the database table). The image source can be in a supported format, in which case the DB2 Image Extender identifies its attributes for storage, or in an unsupported format, in which case the attributes must be specified in the UDF.

Include file

dmbimage.h

Syntax

Store content from buffer or client file

>>-DB2Image--(--dbname--,--content--,--source_format--,--------->
 
>----target_file--,--comment--)--------------------------------><
 

Syntax

Store content from server file

>>-DB2Image--(--dbname--,--source_file--,--source_format--,----->
 
>----stortype--,--comment--)-----------------------------------><
 

Syntax

Store content with user-supplied attributes from buffer or client file

>>-DB2Image--(--dbname--,--content--,--target_file--,----------->
 
>----comment--,--attrs--,--thumbnail--)------------------------><
 

Syntax

Store content with user-supplied attributes from server file

>>-DB2Image--(--dbname--,--source_file--,--stortype--,--comment--,-->
 
>---attrs--,--thumbnail--)-------------------------------------><
 

Syntax

Store content from buffer or client file with format conversion

>>-DB2Image--(--dbname--,--content--,--source_format--,--------->
 
>----target_format--,--target_file--,--comment--)--------------><
 

Syntax

Store content from server file with format conversion

>>-DB2Image--(--dbname--,--source_file--,--source_format--,----->
 
>----target_format--,--target_file--,--comment--)--------------><
 

Syntax

Store content from buffer or client file with format conversion and additional changes

>>-DB2Image--(--dbname--,--content--,--source_format--,--------->
 
>----target_format--,--conversion_options--,--target_file--,---->
 
>----comment--)------------------------------------------------><
 

Syntax

Store content from server file with format conversion and additional changes

>>-DB2Image--(--dbname--,--source_file--,--source_format--,----->
 
>----target_format--,--conversion_options--,--target_file--,---->
 
>----comment--)------------------------------------------------><
 

Parameters (data type)

dbname (VARCHAR(18))
The name of the currently connected database, as indicated by the CURRENT SERVER special register.

content (BLOB(2G) AS LOCATOR)
The host variable that contains the content of the image. The host variable can be of type BLOB, BLOB_FILE, or BLOB_LOCATOR. DB2 promotes the data type of the content to BLOB_LOCATOR and passes the LOB locator to the DB2Image UDF.

source_format (VARCHAR(8))
The format of the source image. A null value, empty string, or the character string ASIS can be specified; in any of these three cases, the Image Extender will attempt to determine the source format automatically. The image will be stored in the same format as its source. See Table 4 for supported image formats.

target_format (VARCHAR(8))
The format of the image after storage. The format of the source image will be converted as appropriate.

target_file (LONG VARCHAR)
The name of the target server file (for storage to a server file), or a null value or empty string (for storage into a database table as a BLOB). The target file name can be a fully qualified name. If the name is unqualified, the DB2IMAGESTORE and DB2MMSTORE environment variables on the server are used to locate the file. If the image is stored with format conversion, the path to the target file needs to be specified in the DB2IMAGEPATH and DB2MMPATH environment variables.

source_file (LONG VARCHAR)
The name of the source server file. The source file name can be a fully qualified name or an unqualified name; it cannot be a null value or empty string. If the name is unqualified, the DB2IMAGEPATH and DB2MMPATH environment variables on the server will be used to locate the file.

stortype (INTEGER)
A value that indicates where the image will be stored. The constant MMDB_STORAGE_TYPE_INTERNAL (value=1) indicates that the image will be stored in the database as a BLOB; the constant MMDB_STORAGE_TYPE_EXTERNAL (value=0) indicates that the image content will be stored in a server file (pointed to from the database).

comment (LONG VARCHAR)
A comment to be stored with the image.

attrs (LONG VARCHAR FOR BIT DATA)
The attributes of the image.

thumbnail (LONG VARCHAR FOR BIT DATA)
A thumbnail of the image.

conversion_options (VARCHAR(100))
Specifies changes, such as rotation and compression, to be applied to the image when it is stored. See Table 5 for the supported conversion options.

Return values (data type)

Handle of the image (DB2IMAGE)

Examples

Insert a record that includes an image for Anita Jones into the employee table. The image source is in a client buffer. Store the image in the table as a BLOB:

EXEC SQL BEGIN DECLARE SECTION
     SQL TYPE IS BLOB (2M) hvImg
EXEC SQL END DECLARE SECTION;
 
EXEC SQL INSERT INTO EMPLOYEE VALUES(
      '128557',
      'Anita Jones',
      DB2IMAGE(
         CURRENT SERVER,
         :hvImg,
         'ASIS',
         CAST(NULL as LONG VARCHAR),
         
         'Anita''s picture'));

Insert a record that includes an image for Robert Smith into the employee table. The image source is in a server file. The employee table record will point to the file. Convert the format of the image from BMP to GIF when stored. Also crop the image to a width of 110 pixels and a height of 150 pixels and compress the image by using LZW type compression:

EXEC SQL INSERT INTO EMPLOYEE VALUES(
      '384779',
      'Robert Smith',
      DB2IMAGE(
         CURRENT SERVER,
         '/employee/pictures/rsmith.bmp',
         'BMP',
         'GIF',
         '-x 110 -y 150 -c 14',
         '',
         'Robert"s picture'));

Insert a record that includes an image for Robert Smith into the employee table. The source image, which is in a server file, has a user-defined format, a height of 640 pixels, and a width of 480 pixels. Store the image as a BLOB:

EXEC SQL BEGIN DECLARE SECTION;
long hvStorageType;
struct {
       short len;
       char data[400];
}hvImgattrs;
EXEC SQL END DECLARE SECTION;
 
DB2IMAGEATTRS    *pimgattr;
 
hvStorageType = MMDB_STORAGE_TYPE_INTERNAL;
 
pimgattr = (DB2IMAGEATTRS *) hvImgattrs.data;
strcpy(pimgattrt>cFormat,"FormatI");
pimgattr>width=640;
pimgattr>height=480;
hvImgattrs.len=sizeof(DB2IMAGEATTRS);
 
EXEC SQL INSERT INTO EMPLOYEE VALUES(
        '128557',
        'Anita Jones',
        DB2IMAGE(
          CURRENT SERVER,
          '/employee/images/ajones.bmp',
          :hvStorageType,
          'Anita''s picture',
          :hvImgattrs,
          CAST(NULL as LONG VARCHAR))
       );


[ Top of Page | Previous Page | Next Page | Table of Contents | Index ]