 |
Informix Guide to SQL: Syntax SQL Statements
|
|
CREATE OPAQUE TYPE
Use the CREATE OPAQUE TYPE statement to create an opaque data type.
Syntax
Usage
The CREATE OPAQUE TYPE statement registers a new opaque type in the database. Dynamic Server stores information on extended data types, including opaque types, in the sysxtdtypes system catalog table.
Privileges on Opaque Types
To create an opaque type, you must have the Resource privilege on the database. When you create the opaque type, only you, the owner, have the Usage privilege on this type. Use the GRANT or REVOKE statements to grant or revoke the Usage privilege to other database users.
To find out what privileges exist on a particular type, check the sysxtdtypes system catalog table for the owner name and the sysxtdtypeauth system catalog table for additional type privileges that might have been granted. For more information on system catalog tables, see the Informix Guide to SQL: Reference.
The DB-Access utility can also display privileges on opaque types.
Naming an Opaque Type
The actual name of an opaque type is an SQL identifier. When you create an opaque type, the name must be unique within a database.
When you create an opaque type in an ANSI-compliant database, owner.type_name must be unique within the database.
The owner name is case sensitive. If you do not put quotes around the owner name, the name of the opaque-type owner is stored in uppercase letters.
INTERNALLENGTH Modifier
The INTERNALLENGTH modifier specifies the size of an opaque type. The way you specify the internal length defines whether the opaque type is fixed length or varying length.
Fixed-Length Opaque Types
A fixed-length opaque type has an internal structure that has a fixed size. To create a fixed-length opaque type, specify the size of the internal structure, in bytes, for the INTERNALLENGTH modifier. The following statement creates a fixed-length opaque type called fixlen_typ. The database server allocates 8 bytes for this type.
Varying-Length Opaque Types
A varying-length opaque type has an internal structure whose size might vary from one instance of the opaque type to another. For example, the internal structure of an opaque type might hold the actual value of a string up to a certain size but beyond this size it might use an LO-pointer to a CLOB to hold the value.
To create a varying-length opaque type, use the VARIABLE keyword for the INTERNALLENGTH modifier. The following statement creates a variable-length opaque type called varlen_typ:
Opaque-Type Modifier
Use modifiers to specify the following optional information:
Defining an Opaque Type
To define the opaque type to the database server, you must provide the following information in the C language:
The following table summarizes the support functions for an opaque type.
Function
|
Purpose
|
Invoked
|
input
|
Converts the opaque type from its external LVARCHAR representation to its internal representation
|
When a client application sends a character representation of the opaque type in an INSERT, UPDATE, or LOAD statement
|
output
|
Converts the opaque type from its internal representation to its external LVARCHAR representation
|
When the database server sends a character representation of the opaque type as a result of a SELECT or FETCH statement
|
receive
|
Converts the opaque type from its internal representation on the client computer to its internal representation on the server computer
Provides platform-independent results regardless of differences between client and server computer types.
|
When a client application sends an internal representation of the opaque type in an INSERT, UPDATE, or LOAD statement
|
send
|
Converts the opaque type from its internal representation on the server computer to its internal representation on the client computer
Provides platform-independent results regardless of differences between client and database server computer types.
|
When the database server sends an internal representation of the opaque type as a result of a SELECT or FETCH statement
|
import
|
Performs any tasks need to convert from the external (character) representation of an opaque type to the internal representation for a bulk copy
|
When DB-Access (LOAD) or the High Performance Loader initiates a bulk copy from a text file to a database
|
export
|
Performs any tasks need to convert from the internal representation of an opaque type to the external (character) representation for a bulk copy
|
When DB-Access (UNLOAD) or the High Performance Loader initiates a bulk copy from a database to a text file
|
importbinary
|
Performs any tasks need to convert from the internal representation of an opaque type on the client computer to the internal representation on the server computer for a bulk copy
|
When DB-Access (LOAD) or the High Performance Loader initiates a bulk copy from a binary file to a database
|
exportbinary
|
Performs any tasks need to convert from the internal representation of an opaque type on the server computer to the internal representation on the client computer for a bulk copy
|
When DB-Access (UNLOAD) or the High Performance Loader initiates a bulk copy from a database to a binary file
|
assign()
|
Performs any processing required before storing the opaque type to disk
This support function must be named assign().
|
When the database server executes an INSERT, UPDATE, and LOAD statement, before it stores the opaque type to disk
|
destroy()
|
Performs any processing necessary before removing a row that contains the opaque type
This support function must be named destroy().
|
When the database server executes the DELETE and DROP TABLE statements, before it removes the opaque type from disk
|
lohandles()
|
Returns a list of the LO-pointer structures (pointers to smart large objects) in an opaque type
|
Whenever the database server must search opaque types for references to smart large objects: when the oncheck utility runs, when an archive is performed
|
compare()
|
Compares two values of the opaque type and returns an integer value to indicate whether the first value is less than, equal to, or greater than the second value
|
When the database server encounters an ORDER BY, UNIQUE, DISTINCT, or UNION clause in a SELECT statement, or when it executes the CREATE INDEX statement to create a B-tree index
|
Once you write the necessary support functions for the opaque type, use the CREATE FUNCTION statement to register these support functions in the same database as the opaque type. Certain support functions convert other data types to or from the new opaque type. After you create and register these support functions, use the CREATE CAST statement to associate each function with a particular cast. The cast must be registered in the same database as the support function.
When you have written the necessary source code to define the opaque type, you then use the CREATE OPAQUE TYPE statement to register the opaque type in the database.
Related Information
Related statements: CREATE CAST, CREATE DISTINCT TYPE, CREATE FUNCTION, CREATE ROW TYPE, CREATE TABLE, and DROP TYPE
For a summary of an opaque type, see the Informix Guide to SQL: Reference.
For information on how to define an opaque type, see Extending Informix Dynamic Server 2000.
For information about the GLS aspects of the CREATE OPAQUE TYPE statement, refer to the Informix Guide to GLS Functionality.
Informix Guide to SQL: Syntax, Version 9.2
Copyright © 1999, Informix Software, Inc. All rights reserved