IBM Books

Image, Audio, and Video Extenders Administration and Programming

Specifying database or file storage

You can store an image, audio, or video object in a database table as a BLOB, or in a server file. If you store the object in a server file, the database points to the file.

If you store the object from a client buffer or client file, you indicate BLOB or server file storage as a result of what you specify in the target_file parameter. If you specify a file name, it indicates that you want to store the object in a server file. If you specify a null value or an empty string, it indicates that you want to store the object as a BLOB in a database table. The data type of the target_file parameter is LONG VARCHAR. If you specify a null value, remember to cast it to a LONG VARCHAR data type.

For example, the following statements in a C application program store a row that includes an image into a database table. The image source is in a client buffer. The image is stored in a server file. The database table points to the server file:

EXEC SQL BEGIN DECLARE SECTION;
  SQL TYPE IS BLOB_LOCATOR Img_buf
EXEC SQL END DECLARE SECTION;
 
EXEC SQL INSERT INTO EMPLOYEE VALUES(
        '128557',
        'Anita Jones',
        DB2IMAGE(
          CURRENT SERVER,
          :Img_buf,
          'ASIS',
          '/employee/images/ajones.bmp',    /* store image in server file */
          'Anita''s picture')
       );

If you store an object from a server file, specify the constant MMDB_STORAGE_TYPE_INTERNAL

to store the object into a database table as a BLOB. If you want to store the object and have its content remain in the server file, specify the constant MMDB_STORAGE_TYPE_EXTERNAL. MMDB_STORAGE_TYPE_INTERNAL has an integer value of 1. MMDB_STORAGE_TYPE_EXTERNAL has an integer value of 0.

For example, in the following C application program, an audio clip is stored in a server file. The source audio content is already in a server file. The store operation places the filename in the database and thus makes the file accessible through SQL statements.

EXEC SQL BEGIN DECLARE SECTION;
  long hvStorageType;
EXEC SQL END DECLARE SECTION;
 
hvStorageType=MMDB_STORAGE_TYPE_EXTERNAL;
 
EXEC SQL INSERT INTO EMPLOYEE VALUES(
        '128557',
        'Anita Jones',
        DB2AUDIO(
          CURRENT SERVER,
          '/employee/sounds/ajones.wav',
          'WAVE',
          :hvStorageType,             /* store audio in server file */
          'Anita''s voice')
       );


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