The DB2Image, DB2Audio, and DB2Video UDFs are overloaded, that is, they have different formats depending on how the UDFs are used. Each UDF has the following formats (the xxxxx shown in the formats can be Image, Audio, or Video):
Format 1: Store an object from a client buffer or client file:
DB2xxxxx( CURRENT SERVER, /* database name name in CURRENT SERVER REGISTER */ content, /* object content */ format, /* source format */ target_file, /* target file name for storage in file server */ /* or NULL for storage in table as BLOB */ comment /* user comment */ );
Format 2: Store an object from a server file:
DB2xxxxx( CURRENT SERVER, /* database name in CURRENT SERVER REGISTER */ source_file, /* source file name */ format, /* source format */ stortype, /* MMDB_STORAGE_TYPE_EXTERNAL=store */ /* in file server*/ /* MMDB_STORAGE_TYPE_INTERNAL=store */ /* as a BLOB*/ comment /* user comment */ );
Format 3: Store an object with user-supplied attributes from a client buffer or client file:
DB2xxxxx( CURRENT SERVER, /* database name in CURRENT SERVER REGISTER */ content, /* object content */ target_file, /* target file name for storage in file server */ /* or NULL for storage in table as BLOB */ comment, /* user comment */ attrs, /* user-supplied attributes */ thumbnail /* thumbnail (image and video only) */ );
Format 4: Store an object with user-supplied attributes from a server file:
DB2xxxxx( CURRENT SERVER, /* database name in CURRENT SERVER REGISTER */ source_file, /* source file name */ stortype, /* MMDB_STORAGE_TYPE_EXTERNAL=store */ /* in file server*/ /* MMDB_STORAGE_TYPE_INTERNAL=store */ /* as a BLOB*/ comment, /* user comment */ attrs, /* user-supplied attributes */ thumbnail /* thumbnail (image and video only) */ );
The DB2Image UDF includes the following additional formats:
Format 5: Store an image from a client buffer or client file with format conversion:
DB2Image( CURRENT SERVER, /* database name in CURRENT SERVER REGISTER */ content, /* object content */ source_format, /* source format */ target_format, /* target format */ target_file, /* target file name for storage in file server */ /* or NULL for storage in table as BLOB */ comment /* user comment */ );
Format 6: Store an image from a server file with format conversion:
DB2Image( CURRENT SERVER, /* database name in CURRENT SERVER REGISTER */ source_file, /* server file name */ source_format, /* source format */ target_format, /* target format */ target_file, /* target file name for storage in file server */ /* or NULL for storage in table as BLOB */ comment /* user comment */ );
Format 7: Store an image from a client buffer or client file with format conversion and additional changes:
DB2Image( CURRENT SERVER, /* database name in CURRENT SERVER REGISTER */ content, /* object content */ source_format, /* source format */ target_format, /* target format */ conversion_options, /* Conversion options */ target_file, /* target file name for storage in file server */ /* or NULL for storage in table as BLOB */ comment /* user comment */ );
Format 8: Store an image from a server file with format conversion and additional changes:
DB2Image( CURRENT SERVER, /* database name in CURRENT SERVER REGISTER */ source_file, /* server file name */ source_format, /* source format */ target_format, /* target format */ conversion_options /* conversion options */ target_file, /* target file name for storage in file server */ /* or NULL for storage in table as BLOB */ comment /* user comment */ );
For example, the following statements in a C application program insert a row that includes an image into the employee table. The source image is in a server file that is named ajones.bmp. The image is stored in the employee table as a BLOB. (This corresponds to format 2 above.)
EXEC SQL BEGIN DECLARE SECTION; long hvStorageType; EXEC SQL END DECLARE SECTION; hvStorageType=MMDB_STORAGE_TYPE_INTERNAL; EXEC SQL INSERT INTO EMPLOYEE VALUES( '128557', /*id*/ 'Anita Jones', /*name*/ DB2IMAGE( /*Image Extender UDF*/ CURRENT SERVER, /*database*/ '/employee/images/ajones.bmp', /*source file */ 'ASIS', /*keep the image format*/ :hvStorageType /*store image in DB as BLOB*/ 'Anita''s picture') /*comment */ );
The following statements in a C application program store the same row into the employee table as in the previous example. However here the image is converted from BMP to GIF format as it is stored. (This corresponds to format 6 above.)
EXEC SQL INSERT INTO EMPLOYEE VALUES( '128557', /*id*/ 'Anita Jones', /*name*/ DB2IMAGE( /*Image Extender UDF* CURRENT SERVER, /*database*/ '/employee/images/ajones.bmp', /*source file */ 'ASIS', /*source image format*/ 'GIF', /*target image format*/ 'Anita''s picture') /*comment*/ );
When you store an image, audio, or video object, the extender computes attributes such as the number of colors used in the image, audio playing time, or video compression format. If you store an object with an unrecognized format, you need to provide these attributes as input to the UDF. The extender stores the attributes in the database along with other attributes, such as comments about the object and the identification of the user who stored the object. These attributes are then available for you to use in queries.