![]() |
|
The image data type is an example of a varying-length opaque data type written in C. The image data type encapsulates an image such as a JPEG, GIF, or PPM file. If the image is less than 2 kilobytes, the data structure for the data type stores the image directly. However, if the image is greater than 2 kilobytes, the data structure stores a reference (an LO-pointer structure) to a smart large object that contains the image data. An image stored in the smart large object can be referenced by multiple rows, but the database server only needs to store a single copy of it in an sbspace.
This section briefly outlines how to create the image data type.
The following statements shows the internal structure for the image data type in the database:
The following table shows possible function signatures for the basic support functions of the image data type.
The image data type has an embedded smart large object. Therefore, it has the following additional support functions.
The assign() function decides whether to store the image directly in the row or in a separate smart large object. This simple varying-length opaque data type does not require a destroy() function.
The following example shows the SQL statements that register the image data type and its basic support functions in the database:
The CREATE OPAQUE TYPE statement registers the image data type, which has the following characteristics:
The CREATE FUNCTION statements register the following basic support functions:
This example also shows the CREATE CAST statements to create the appropriate cast definitions for the input, output, receive, and send support functions. For more information on casts, see Creating Casts for Opaque Data Types.
The following example shows the SQL statements that register the other support functions for the image data type in the database:
The CREATE FUNCTION statements register the following support functions:
This example also shows the CREATE CAST statements to create the cast definitions for the import, export, importbinary, and exportbinary support functions. For more information on these casts, see Creating Casts for Opaque Data Types.
The CREATE OPAQUE TYPE statement in the example in Registering the image Opaque Data Typecreates the image data type with the Usage privilege granted to the owner (the person who ran the CREATE OPAQUE TYPE statement). The following GRANT statement allows all users of the database to use the image data type in SQL statements:
The CREATE FUNCTION statements in the two previous examples register the support functions for the image data type with the Execute privilege granted to the owner (the person who ran the CREATE FUNCTION statements). The following GRANT statements grant the Execute privilege to all users of the database on the support statements that are defined as explicit casts:
The image data type has the following end-user functions:
The actual code for the end-user functions would be written in the C language and put in the image.so shared-object file. The following SQL statements register the end-user functions for the image opaque data type with the database:
Suppose you decide that the default secondary access method, a generic B-tree index, does not adequately handle data in columns of type image. Because the image data type holds spatial data, it is a good candidate for an R-tree index. To use an R-tree index, you must first install a spatial DataBlade module that implements the R-tree index. For more information about R-trees, refer to the user guide for the DataBlade module and to the Informix R-Tree Index User's Guide.