DB2Image、DB2Audio 及 DB2Video UDF 可被超載, 也就是說其格式隨使用 UDF 的方式而有所不同。UDF 具有下列格式 (格式中顯示的 xxxxx 可以是 Image、Audio 或 Video):
格式 1:儲存一個來自從屬站緩衝區或從屬站檔案的物件:
DB2xxxxx( CURRENT SERVER, /* database name name in CURRENT SERVER REGISTER */ content, /* object content */ format, /* source format */ target_file, /* target file name for storage in file server */ /* or NULL for storage in table as BLOB */ comment /* user comment */ );
格式 2:儲存來自伺服器檔案的物件:
DB2xxxxx( CURRENT SERVER, /* database name in CURRENT SERVER REGISTER */ source_file, /* source file name */ format, /* source format */ stortype, /* MMDB_STORAGE_TYPE_EXTERNAL=store */ /* in file server*/ /* MMDB_STORAGE_TYPE_INTERNAL=store */ /* as a BLOB*/ comment /* user comment */ );
格式 3:儲存從屬站緩衝區或檔案中具有使用者提供之屬性的物件:
DB2xxxxx( CURRENT SERVER, /* database name in CURRENT SERVER REGISTER */ content, /* object content */ target_file, /* target file name for storage in file server */ /* or NULL for storage in table as BLOB */ comment, /* user comment */ attrs, /* user-supplied attributes */ thumbnail /* thumbnail (image and video only) */ );
格式 4:儲存伺服器檔案中具有使用者提供之屬性的物件:
DB2xxxxx( CURRENT SERVER, /* database name in CURRENT SERVER REGISTER */ source_file, /* source file name */ stortype, /* MMDB_STORAGE_TYPE_EXTERNAL=store */ /* in file server*/ /* MMDB_STORAGE_TYPE_INTERNAL=store */ /* as a BLOB*/ comment, /* user comment */ attrs, /* user-supplied attributes */ thumbnail /* thumbnail (image and video only) */ );
DB2Image UDF 包括下列附加的格式:
格式 5:儲存來自從屬站緩衝 區或從屬站檔案,並做格式轉換的影像:
DB2Image( CURRENT SERVER, /* database name in CURRENT SERVER REGISTER */ content, /* object content */ source_format, /* source format */ target_format, /* target format */ target_file, /* target file name for storage in file server */ /* or NULL for storage in table as BLOB */ comment /* user comment */ );
格式 6:儲存來自伺服器檔 案,並做格式轉換的影像:
DB2Image( CURRENT SERVER, /* database name in CURRENT SERVER REGISTER */ source_file, /* server file name */ source_format, /* source format */ target_format, /* target format */ target_file, /* target file name for storage in file server */ /* or NULL for storage in table as BLOB */ comment /* user comment */ );
格式 7:儲存來自從 屬站緩衝區從屬站檔案,並做格式轉換和額外變更的影像:
DB2Image( CURRENT SERVER, /* database name in CURRENT SERVER REGISTER */ content, /* object content */ source_format, /* source format */ target_format, /* target format */ conversion_options, /* Conversion options */ target_file, /* target file name for storage in file server */ /* or NULL for storage in table as BLOB */ comment /* user comment */ );
格式 8:儲存來自伺服器檔 案,並做格式轉換和額外變更的影像:
DB2Image( CURRENT SERVER, /* database name in CURRENT SERVER REGISTER */ source_file, /* server file name */ source_format, /* source format */ target_format, /* target format */ conversion_options /* conversion options */ target_file, /* target file name for storage in file server */ /* or NULL for storage in table as BLOB */ comment /* user comment */ );
例如,下列在 C 應用程式中的陳述式插入了將影像併入員工表格的列。來源影像為名 為 ajones.bmp 的伺服器檔案。影像以 BLOB 形式儲存在員工表格內。(它對應於上述格式 2。)
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', /*source file */ 'ASIS', /*keep the image format*/ :hvStorageType /*store image in DB as BLOB*/ 'Anita''s picture') /*comment */ );
下列在 C 應用程式中的陳述式將同一橫列儲存至前例中的員工表格。但此處在儲存影像時, 其格式 BMP 被轉換成 GIF。(它對應 於上述格式 6。)
EXEC SQL INSERT INTO EMPLOYEE VALUES( '128557', /*id*/ 'Anita Jones', /*name*/ DB2IMAGE( /*Image Extender UDF* CURRENT SERVER, /*database*/ '/employee/images/ajones.bmp', /*source file */ 'ASIS', /*source image format*/ 'GIF', /*target image format*/ 'Anita''s picture') /*comment*/ );
當您儲存影像音效或視訊物件時,Extender 會計算許多屬性, 諸如影像中所使用的顏色數、音效播放時間或視訊壓縮格式。若儲存的物件含有無法辨識的格式,您必須提供這些屬性作為 UDF 的輸入。 Extender 會連同其它屬性 (如有關物件的註解及儲存物件之使用者的識別) 將這些屬性儲存在資料庫中。 然後您便可以在查詢中使用這些屬性。