Persistent user data
The term user data is the information that a purpose function saves in shared memory. The access method defines a user-data type and then allocates an area of memory with the appropriate size and duration.
In the following example, the user data stores the information
that the access method needs for a PER_STATEMENT duration.
Figure 1. Allocating
user-data memory
MI_AM_TAB_DESC * tableDesc; /* Pointer to table descriptor */
typedef enum my_col_types
{
MY_INT = 1,
MY_CHAR
} my_col_type;
typedef struct my_row
{
mi_integer rowid;
mi_integer fragid;
char data[500];
struct my_row *next;
} my_row_t;
typedef struct statement_data
{
MI_DATUM *retrow; /*Points to data in memory*/
my_col_type col_type[10]; /*Data types in the index keys*/
mi_boolean is_null[10]; /*Array of true and false indicators*/
my_row_t *current index entry;
MI_CONNECTION *conn;
MI_CALLBACK_HANDLE *error_cback;
} statement_data_t;
/*Allocate memory*/
statement_data_t* my_data = (statement_data_t*)
mi_dalloc(sizeof(statement_data_t), PER_STATEMENT);
mi_tab_setuserdata(tableDesc, (void *) my_data); /*Store pointer*/
The following table shows accessor functions that the
virtual-index interface (VII) provides to store and retrieve user
data.
Descriptor | User-data duration | Stores pointer to user data | Retrieves pointer to user data |
---|---|---|---|
Table descriptor | PER_STATEMENT | mi_tab_setuserdata() | mi_tab_userdata() |
Scan descriptor | PER COMMAND | mi_scan_setuserdata() | mi_scan_userdata() |
The following example shows how to retrieve the pointer
from the table descriptor that the mi_tab_setuserdata() function
set in Figure 1:
my_data=(statement_data_t *)mi_tab_userdata(tableDesc);