Die benutzerdefinierten Funktionen (UDFs) "DB2Image", "DB2Audio" und "DB2Video" sind mehrfach belegt. Dies bedeutet, daß sie abhängig von der Verwendung der UDFs unterschiedliche Formate haben. Jede UDF hat die folgenden Formate (die Zeichenfolge xxxxx in den Formaten kann für Image, Audio oder Video stehen):
Format 1: Objekt aus einem Client-Puffer oder einer Client-Datei speichern:
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 */ );
Format 2: Objekt aus einer Server-Datei speichern:
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 */ );
Format 3: Objekt mit vom Benutzer angegebenen Attributen aus einem Client-Puffer oder einer Client-Datei speichern:
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) */ );
Format 4: Objekt mit vom Benutzer angegebenen Attributen aus einer Server-Datei speichern:
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) */ );
Zu der UDF DB2Image gehören zusätzlich die folgenden Formate:
Format 5: Abbild aus einem Client-Puffer oder einer Client-Datei mit Formatumsetzung speichern:
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 */ );
Format 6: Abbild aus einer Server-Datei mit Formatumsetzung speichern:
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 */ );
Format 7: Abbild aus einem Client-Puffer oder einer Client-Datei mit Formatumsetzung und zusätzlichen Änderungen speichern:
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 */ );
Format 8: Abbild aus einer Server-Datei mit Formatumsetzung und zusätzlichen Änderungen speichern:
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 */ );
Die folgenden Anweisungen in einem C-Anwendungsprogramm fügen beispielsweise eine Zeile ein, mit der ein Abbild zur Tabelle 'employee' hinzugefügt wird. Das Quellenabbild befindet sich in einer Server-Datei mit dem Namen ajones.bmp. Das Abbild wird in der Tabelle 'employee' als BLOB (Binary Large Object) gespeichert. (Dies entspricht dem oben aufgeführten Format 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 */ );
Die folgenden Anweisungen in einem C-Anwendungsprogramm speichern dieselbe Zeile wie im vorigen Beispiel in der Tabelle 'employee'. In diesem Fall wird jedoch das Abbild beim Speichern vom BMP-Format in das GIF-Format umgesetzt. (Dies entspricht dem oben aufgeführten Format 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*/ );
Wenn Sie ein Abbild-, Audio- oder Videoobjekt speichern, berechnet der Extender die Attribute, wie beispielsweise die Anzahl der im Abbild verwendeten Farben, die Spieldauer des Audioclips oder das Videokomprimierungsformat. Wenn Sie ein Objekt mit einem nicht erkannten Format speichern, müssen Sie diese Attribute als Eingabe für die benutzerdefinierte Funktion angeben. Der Extender speichert diese und andere Attribute, wie beispielsweise Kommentare über das Objekt oder die ID des Benutzers, der das Objekt gespeichert hat, in der Datenbank. Diese Attribute können anschließend in Abfragen verwendet werden.