調用存儲引擎的第一個方法是建立新的處理程序實例。在定義 handlerton 結構前,必須先聲明實例化函數原型,例如 CSV 引擎:
static handler* tina_create_handler(TABLE *table);
該函數接收表指針,返回處理程序對象指針。隨後在 handlerton 的第 21 個元素(函數指針)中指定該函數,標識其負責創建新實例。
static handler *myisam_create_handler(TABLE *table) {
return new ha_myisam(table);
}
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) {}
除基類 handler() 初始化外,還包含引擎特有的成員初始化。
ha_example::ha_example(TABLE *table_arg)
: handler(&example_hton, table_arg) {}
僅完成基類 handler() 初始化,這是最低要求的實現。
handler* xxx_create_handler(TABLE*)。handlerton 中註冊該函數指針。handler(handlerton*, TABLE*)。