15.5. Handling Handler Instantiation
The first method call your storage engine needs to support is the
call for a new handler instance.
Before the handlerton
is defined in the storage
engine source file, a function header for the instantiation
function must be defined. Here is an example from the
CSV
engine:
static handler* tina_create_handler(TABLE *table);
As you can see, the function accepts a pointer to the table the
handler is intended to manage, and returns a handler object.
After the function header is defined, the function is named with a
function pointer in the create()
handlerton
element, identifying the function as
being responsible for generating new handler instances.
Here is an example of the MyISAM
storage
engine's instantiation function:
static handler *myisam_create_handler(TABLE *table)
{
return new ha_myisam(table);
}
This call then works in conjunction with the storage engine's
constructor. Here is an example from the
FEDERATED
storage engine:
ha_federated::ha_federated(TABLE *table_arg)
:handler(&federated_hton, table_arg),
mysql(0), stored_result(0), scan_flag(0),
ref_length(sizeof(MYSQL_ROW_OFFSET)), current_position(0)
{}
And here's one more example from the EXAMPLE
storage engine:
ha_example::ha_example(TABLE *table_arg)
:handler(&example_hton, table_arg)
{}
The additional elements in the FEDERATED
example are extra initializations for the handler. The minimum
implementation required is the handler()
initialization shown in the EXAMPLE
version.