The DB2 extenders provide user-defined functions to store, access, and manipulate image, audio, and video data in a database. You code requests for these UDFs in your application program using SQL statements in the same way that you request SQL built-in functions. Like built-in functions, UDFs are run in the database server.
The following SQL statements in a C application program request an Image Extender UDF named DB2Image to store an image in a database table; the content of the source image is in a server file:
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', /*image content*/ 'ASIS', /*keep the image format*/ :hvStorageType, /*store image in DB as BLOB* 'Anita''s picture') /*comment*/ );
You use extender application programming interfaces to display images and play audio or video objects. You code these APIs using client function calls in C. The functions are run in your database client workstation.
The following C statements include an API that is named DBiBrowse. The API retrieves the data for an image handle and starts a browser to display the image:
EXEC SQL BEGIN DECLARE SECTION; char hvImg_hdl[251]; EXEC SQL END DECLARE SECTION EXEC SQL SELECT PICTURE INTO :hvImg_hdl WHERE NAME= 'Robert Smith'; rc=DBiBrowse( "ib %s", /*image browser*/ MMDB_PLAY_HANDLE, /*use image handle*/ hvImg_hdl, /*image handle*/ MMDB_PLAY_NO_WAIT); /*run browser independently*/
UDFs must run under the user ID of the instance: DB2 extender UDFs must run under the same user ID as the DB2 extender instance. In addition, if you create a DB2 extender instance or use an existing DB2 extender instance, the UDFs must run under the same user ID as the DB2 instance.
DB2 must be configured properly: You must configure DB2 properly to ensure the proper operation of the DB2 extenders, especially the proper operation of DB2 extender UDFs. In particular, the APP_CTL_HEAP_SZ database configuration parameter must be set properly.