diff --git a/mysql-test/t/example_i_s.test b/mysql-test/t/example_i_s.test new file mode 100644 index 00000000000..b23ef1c4a11 --- /dev/null +++ b/mysql-test/t/example_i_s.test @@ -0,0 +1,4 @@ +INSTALL PLUGIN EXAMPLE_I_S SONAME 'ha_example.so'; +UNINSTALL PLUGIN EXAMPLE_I_S; +FLUSH TABLES; +INSTALL PLUGIN EXAMPLE_I_S SONAME 'ha_example.so'; diff --git a/storage/example/ha_example.cc b/storage/example/ha_example.cc index 13c8389fee7..09609bb7649 100644 --- a/storage/example/ha_example.cc +++ b/storage/example/ha_example.cc @@ -96,8 +96,11 @@ #include "my_dbug.h" #include "mysql/plugin.h" +#include "sql/field.h" #include "sql/sql_class.h" #include "sql/sql_plugin.h" +#include "sql/sql_show.h" +#include "sql/table.h" #include "typelib.h" static handler *example_create_handler(handlerton *hton, TABLE_SHARE *table, @@ -884,6 +887,62 @@ static SHOW_VAR func_status[] = { SHOW_SCOPE_GLOBAL}, {0, 0, SHOW_UNDEF, SHOW_SCOPE_UNDEF}}; +#define EXAMPLE_FIELD_INFO(_name_, _len_, _type_, _flag_) \ + { _name_, _len_, _type_, 0, _flag_, nullptr, 0 } + +#define EXAMPLE_FIELD_INFO_END \ + EXAMPLE_FIELD_INFO(nullptr, 0, MYSQL_TYPE_NULL, 0) + +static ST_FIELD_INFO example_i_s_fields_info[] = { + EXAMPLE_FIELD_INFO("NAME", NAME_LEN + 1, MYSQL_TYPE_STRING, 0), + EXAMPLE_FIELD_INFO("AGE", sizeof(uint64_t), MYSQL_TYPE_LONGLONG, 0), + EXAMPLE_FIELD_INFO_END}; + +static int example_i_s_fill_table(THD *thd, TABLE_LIST *tables, Item *) { + DBUG_TRACE; + Field **field = tables->table->field; + DBUG_ASSERT(field != nullptr); + field[0]->store("Shuai Lou", 9, system_charset_info); + field[1]->store(21, true); + int ret = static_cast(schema_table_store_record(thd, tables->table)); + return ret; +} + +static int example_i_s_init_func(void *p) { + DBUG_TRACE; + DBUG_ASSERT(p != nullptr); + ST_SCHEMA_TABLE *schema; + schema = (ST_SCHEMA_TABLE *)p; + schema->fields_info = example_i_s_fields_info; + schema->fill_table = example_i_s_fill_table; + return 0; +} + +static int example_i_s_deinit_func(void *p MY_ATTRIBUTE((__unused__))) { + DBUG_TRACE; + return 0; +} + +static struct st_mysql_information_schema example_i_s_info = { + MYSQL_INFORMATION_SCHEMA_INTERFACE_VERSION}; + +struct st_mysql_plugin example_information_schemna = { + MYSQL_INFORMATION_SCHEMA_PLUGIN, + &example_i_s_info, + "EXAMPLE_I_S", + "Shuai Lou, GreatOpenSource", + "Example information schema", + PLUGIN_LICENSE_GPL, + example_i_s_init_func, + nullptr, + example_i_s_deinit_func, + 0x0001, /* version number (0.1) */ + nullptr, /* status variables */ + nullptr, /* system variables */ + nullptr, /* config options */ + 0, /* flags */ +}; + mysql_declare_plugin(example){ MYSQL_STORAGE_ENGINE_PLUGIN, &example_storage_engine, @@ -899,4 +958,5 @@ mysql_declare_plugin(example){ example_system_variables, /* system variables */ NULL, /* config options */ 0, /* flags */ -} mysql_declare_plugin_end; +}, + example_information_schemna mysql_declare_plugin_end;