IBM Books

Image, Audio, and Video Extenders Administration and Programming

Retrieving an object to a server file

You can use the Content UDF to retrieve an image, audio, or video object to a server file without format conversion. In addition, you can use the Content UDF to retrieve an image to a server file with format conversion.

When you retrieve an image, audio, or video object to a file on the server without conversion, specify the object's handle, the target file name, and an overwrite indicator. The overwrite indicator tells the extender whether to overwrite the target file with the retrieved data if the target file already exists on the server. If the target file does not exist, the extender creates the target file on the server.

If you specify an overwrite indicator value of 1, the extender overwrites the target file with the retrieved data. If you specify an overwrite indicator value of 0, the extender does not overwrite the target file, thus the data is not retrieved.

The overwrite indicator is ignored if the object to be retrieved is stored in a database table as a BLOB. The target file will be created or overwritten no matter what is specified for the overwrite indicator.

When you retrieve an object to a server file, it returns the name of the server file. For example, the following statement in a C application program retrieves a video to a file on the server. The file name of the server file is stored in the host variable hvVid_fname.

EXEC SQL BEGIN DECLARE SECTION;
struct{
       short len;
       char data[250]; 
      }hvVid_fname[;
EXEC SQL END DECLARE SECTION;
 
EXEC SQL SELECT CONTENT(
        VIDEO,                               /* video handle */
        '/employee/videos/ajones.mpg',       /* server file */
        1)                                   /* overwrite target file */
     INTO :hvVid_fname;
     FROM EMPLOYEE
     WHERE NAME = 'Anita Jones';

Using the Content UDF to retrieve an object to a server file without conversion is appropriate when the object is stored in a database table as a BLOB. If the object is stored in a server file, it might be more efficient to copy the content of the source file to the target file.

When you retrieve an image to a server file with format conversion, specify the image handle, the target file name, an overwrite target indicator, and the target format. Table 4 identifies what format conversions are allowed. You can also choose to specify a null value or empty string for the target format or the string ASIS. In this case, the retrieved image will have the same format as the source.

For example, the following statements in a C application program retrieve an image to a file on the server. The source image is in bitmap format and is stored in a database table as a BLOB. The retrieved image is converted to GIF format. The file name of the server file is stored in the host variable hvImg_fname.

EXEC SQL BEGIN DECLARE SECTION;
  struct{
        short len;
        char [400]; 
        }hvImg_fname[;
EXEC SQL END DECLARE SECTION;
 
EXEC SQL SELECT CONTENT(
        PICTURE,                             /* image handle */
        '/employee/images/ajones.gif',       /* target file */
        1,                                   /* overwrite target file */
        'GIF')                               /* target format */
     INTO :hvImg_fname
     FROM EMPLOYEE
     WHERE NAME = 'Anita Jones';

The server file must be accessible: When you retrieve an object to a server file, you must specify the target file's fully qualified name. Alternatively, you must ensure that the DB2IMAGEEXPORT, DB2AUDIOEXPORT, and DB2VIDEOEXPORT environment variables are set to properly resolve an incomplete file name specification.


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