IBM Books

Image, Audio, and Video Extenders Administration and Programming

Storing an object with user-supplied attributes

When you store an image, audio, or video object, you are not limited to formats that the extenders understand. You can specify your own format. Because the extenders do not understand the format, you must specify the attributes of the source object. Assign the attribute values in an attribute structure. The attribute structure must be stored in the data field of the LONG VARCHAR FOR BIT DATA variable in the UDF.

The UDF code on the server always expects data in "big endian format". Big endian format is a format used by most UNIX platforms. If you are storing an object in "little endian format", you need to prepare the user-supplied attribute data so that UDF code on the server can correctly process it. Little endian format is a format typically used in an Intel(R) and other microprocessor platform. (Even if you are not storing the object in little endian format, it is a good idea to prepare the user-supplied attrubute data.) Use the DBiPrepareAttrs API to prepare attributes for image objects. Use the DBaPrepareAttrs API to prepare attributes for audio objects. Use the DBvPrepareAttrs API to prepare attributes for video objects.

For example, the following statements in a C application program store a row that includes an image in a database 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. Notice that the attributes are prepared before the image is stored.

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(pimgattr>format,"FormatI");
pimgattr>width=640;
pimgattr>height=480;
hvImgattrs.len=sizeof(DB2IMAGEATTRS);
 
DBiPrepareAttrs(pimgattr);
 
DBEXEC SQL INSERT INTO EMPLOYEE VALUES(
        '128557',
        'Anita Jones',
        DB2IMAGE(
          CURRENT SERVER,
          '/employee/images/ajones.bmp',
          :hvStorageType,
          'Anita''s picture',
          :hvImgattrs,                   /* user-specified attributes */
          CAST(NULL as LONG VARCHAR)
       );

The following statement in a C application program stores a row that includes an audio clip in a database table. The source audio clip, which is in a server file, has a user-defined format, a sampling rate of 44.1 kHz, and has two recorded channels. The audio clip is not MIDI, so empty strings are specified for tracknames and instruments.

EXEC SQL BEGIN DECLARE SECTION;
long hvStorageType;
struct (
       short len;
       char data[600];
}hvAudattr;
EXEC SQL END DECLARE SECTION;
 
MMDBAudioAttrs          *paudiattr;
 
hvStorageType=MMDB_STORAGE_TYPE_INTERNAL;
 
paudioattr=(MMDBAudioAttrs *) hvAudattr.data;
strcpy(paudioAttr>cFormat,"FormatA");
paudioAttr>ulSamplingRate=44100;
paudioAttr>usNumChannels=2;
hvAudattrs.len=sizeof(MMDBAudioAttrs);
 
DBaPrepareAttrs(paudioAttr);
 
EXEC SQL INSERT INTO EMPLOYEE VALUES(
        '128557',
        'Anita Jones',
        DB2AUDIO(
          CURRENT SERVER,
          '/employee/sounds/ajones.aud',
          :hvStorageType,
          'Anita''s voice',
          :hvAudattr)                   /* user-specified attributes */
       );


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