You can use the Content UDF to retrieve an image, audio, or video object to a client buffer or client file without format conversion. In addition, you have the option of having the Image Extender convert the format of an image when it is retrieved.
Use a LOB locator to retrieve an image, audio, or video object to a client buffer, or retrieve the LOB. Use a file reference variable to retrieve an image, audio, or video object to a client file.
Retrieving an image, audio, or video object to a client buffer using a host variable, or to a client file using a file reference variable is appropriate when the content of the object is stored in a database table as a BLOB. If the content is in a server file, it might be more efficient to copy the content from the server file to the client file.
Specify the handle of the object. Optionally, you can also specify the offset, starting at byte 1, where retrieval is to start, and the number of bytes that you want to retrieve.
The following statements in a C application program use a LOB locator named audio_loc to retrieve an audio clip into a client buffer.
EXEC SQL BEGIN DECLARE SECTION; SQL TYPE IS BLOB_LOCATOR audio_loc; EXEC SQL END DECLARE SECTION; EXEC SQL SELECT CONTENT( SOUND) /* audio handle */ INTO :audio_loc FROM EMPLOYEE WHERE NAME = 'Anita Jones';
Make sure that you have enough UDF memory: When you retrieve an object to a client buffer, you need to make sure that the UDF_MEM_SZ parameter in the Database Manager Configuration is set to 4MB or greater. You can update the UDF_MEM_SZ parameter with the DB2 command UPDATE DATABASE MANAGER CONFIGURATION. For information on the UPDATE DATABASE MANAGER command, see the publication DB2 Command Reference.
Use a LOB locator to retrieve a stored image to a client buffer with format conversion, or retrieve the LOB. Use a file reference variable to retrieve a stored image to a client file with format conversion.
Retrieving an image to a client buffer using a host variable, or to a client file using a file reference variable, is appropriate when the content of the image is stored in a database table as a BLOB. If the content is in a server file, it might be more efficient to copy the content from the server file to the client file.
When you retrieve an image with format conversion, you need to specify its target format, that is, the converted format. Table 4 identifies the format conversions that are allowed. You can also specify conversion options that identify additional changes, such as rotation or scaling, to be applied to the retrieved image. Table 5 lists the conversion options that you can specify.
For example, the following statements in a C application program retrieve an image to a client file. The source image is in bitmap format and it is stored in a database table as a BLOB. The retrieved image is converted to GIF and it is scaled to 3 times its original size.
EXEC SQL BEGIN DECLARE SECTION; SQL TYPE IS BLOB_FILE Img_file; EXEC SQL END DECLARE SECTION; strcpy (Img_file.name, "/employee/images/ajones.gif"); Img_file.name_length= strlen(Img_file.name); Img_file.file_options= SQL_FILE_CREATE; EXEC SQL SELECT CONTENT( PICTURE, /* image handle */ 'GIF', /* target format */ '-s 3.0') /* conversion options */ INTO :Img_file, FROM EMPLOYEE WHERE NAME = 'Anita Jones';