Write purpose functions
The Virtual-Table Interface (VTI) specifies the parameters and return values for a limited set of UDRs, called purpose functions, that correspond to one or more SQL statements.
For most SQL statements, the database server attempts to start a sequence of task-specific purpose functions to process the statement. You choose the tasks and SQL statements that the access method supports and then write the appropriate purpose functions for those tasks.
Invoking statement or command | Purpose-function prototype |
---|---|
All If you do not supply am_open and am_close, open and close the data source in am_getnext. |
|
CREATE TABLE | am_create(MI_AM_TABLE_DESC *) |
DROP TABLE | am_drop(MI_AM_TABLE_DESC *) |
INSERT | am_insert(MI_AM_TABLE_DESC *, MI_ROW *,
mi_integer *) |
DELETE | am_delete(MI_AM_TABLE_DESC *, mi_integer
*) |
SELECT INSERT, UPDATE, DELETE WHERE... |
|
SELECT with join | am_rescan(MI_AM_SCAN_DESC *) |
SELECT using an index | am_getbyid(MI_AM_TABLE_DESC *, MI_ROW **,
mi_integer) |
UPDATE | am_update(MI_AM_TABLE_DESC *, MI_ROW *,
mi_integer ) |
UPDATE STATISTICS | am_stats(MI_AM_TABLE_DESC *, MI_AM_TSTATS_DESC
*) |
oncheck utility | am_check(MI_AM_TABLE_DESC *, mi_integer) |
You must assign unique names, such as image_open, docfile_open, and getnext_record.
When the database server calls a purpose function, it passes the appropriate parameters for the current database server activity. Most parameters reference the opaque descriptor data structures. The database server creates and passes descriptors to describe the state of the table and the current SQL statement or oncheck command.
As you write the purpose functions, adhere to the syntax provided for each function.
- Opening and initializing files or smart large objects, as well as closing them again at the end of processing
- Creating new tables
- Inserting, updating, or deleting data
- Running the oncheck utility
- Optimizing queries
The following sections name the functions that the database server calls for the specific purposes in the previous list. The access-method library might contain a separate function for each of several purpose-function prototypes or supply only an am_getnext purpose function as the entry point for all the essential access-method processing.