From d553b667911304ae14f9bed3b10fd3c1b77da649 Mon Sep 17 00:00:00 2001 From: unknown Date: Fri, 30 Sep 2005 16:26:48 -0700 Subject: Move handler specific options into handlerton flag check BUG#13108 mysql-test/r/federated.result: added test results for federated alter table mysql-test/t/federated.test: added test for federated alter table sql/examples/ha_example.cc: supports table re-creation sql/examples/ha_tina.cc: supports table re-creation sql/ha_blackhole.cc: supports table re-creation sql/ha_federated.cc: added flag for not supporting alter sql/ha_heap.cc: supports table recreation sql/ha_myisam.cc: supports table recreation sql/ha_myisammrg.cc: supports table re-creation sql/handler.cc: implemented flag check function sql/handler.h: added additional handlerton flags created a function to test flags replace ha_supports_generate macro with call to flag check sql/sql_delete.cc: replaced ha_supports_generate with handlerton flag check sql/sql_table.cc: added check for handlerton check for alter support --- sql/examples/ha_example.cc | 2 +- sql/examples/ha_tina.cc | 2 +- sql/ha_blackhole.cc | 2 +- sql/ha_federated.cc | 2 +- sql/ha_heap.cc | 2 +- sql/ha_myisam.cc | 2 +- sql/ha_myisammrg.cc | 2 +- sql/handler.cc | 17 +++++++++++++++++ sql/handler.h | 13 +++++-------- sql/sql_delete.cc | 5 +++-- sql/sql_table.cc | 10 ++++++++++ 11 files changed, 42 insertions(+), 17 deletions(-) (limited to 'sql') diff --git a/sql/examples/ha_example.cc b/sql/examples/ha_example.cc index cc4ad3eb535..d809398b69f 100644 --- a/sql/examples/ha_example.cc +++ b/sql/examples/ha_example.cc @@ -90,7 +90,7 @@ handlerton example_hton= { NULL, /* create_cursor_read_view */ NULL, /* set_cursor_read_view */ NULL, /* close_cursor_read_view */ - HTON_NO_FLAGS + HTON_CAN_RECREATE }; /* Variables for example share methods */ diff --git a/sql/examples/ha_tina.cc b/sql/examples/ha_tina.cc index 5663cd829bd..559fdfbbbd9 100644 --- a/sql/examples/ha_tina.cc +++ b/sql/examples/ha_tina.cc @@ -71,7 +71,7 @@ handlerton tina_hton= { NULL, /* create_cursor_read_view */ NULL, /* set_cursor_read_view */ NULL, /* close_cursor_read_view */ - HTON_NO_FLAGS + HTON_CAN_RECREATE }; /***************************************************************************** diff --git a/sql/ha_blackhole.cc b/sql/ha_blackhole.cc index f089b67d678..57882e638d7 100644 --- a/sql/ha_blackhole.cc +++ b/sql/ha_blackhole.cc @@ -43,7 +43,7 @@ handlerton blackhole_hton= { NULL, /* create_cursor_read_view */ NULL, /* set_cursor_read_view */ NULL, /* close_cursor_read_view */ - HTON_NO_FLAGS + HTON_CAN_RECREATE }; /***************************************************************************** diff --git a/sql/ha_federated.cc b/sql/ha_federated.cc index 9a8b5eb794d..f2caca7f012 100644 --- a/sql/ha_federated.cc +++ b/sql/ha_federated.cc @@ -713,7 +713,7 @@ handlerton federated_hton= { NULL, /* create_cursor_read_view */ NULL, /* set_cursor_read_view */ NULL, /* close_cursor_read_view */ - HTON_NO_FLAGS + HTON_ALTER_NOT_SUPPORTED }; diff --git a/sql/ha_heap.cc b/sql/ha_heap.cc index fafd597e858..ad7da559ff4 100644 --- a/sql/ha_heap.cc +++ b/sql/ha_heap.cc @@ -40,7 +40,7 @@ handlerton heap_hton= { NULL, /* create_cursor_read_view */ NULL, /* set_cursor_read_view */ NULL, /* close_cursor_read_view */ - HTON_NO_FLAGS + HTON_CAN_RECREATE }; /***************************************************************************** diff --git a/sql/ha_myisam.cc b/sql/ha_myisam.cc index 02769c1eb31..c9e69b377d0 100644 --- a/sql/ha_myisam.cc +++ b/sql/ha_myisam.cc @@ -73,7 +73,7 @@ handlerton myisam_hton= { MyISAM doesn't support transactions and doesn't have transaction-dependent context: cursors can survive a commit. */ - HTON_NO_FLAGS + HTON_CAN_RECREATE }; // collect errors printed by mi_check routines diff --git a/sql/ha_myisammrg.cc b/sql/ha_myisammrg.cc index 8347dcdaa3e..7a93015ecaa 100644 --- a/sql/ha_myisammrg.cc +++ b/sql/ha_myisammrg.cc @@ -51,7 +51,7 @@ handlerton myisammrg_hton= { NULL, /* create_cursor_read_view */ NULL, /* set_cursor_read_view */ NULL, /* close_cursor_read_view */ - HTON_NO_FLAGS + HTON_CAN_RECREATE }; diff --git a/sql/handler.cc b/sql/handler.cc index 39d9b706ed2..5221ccbb7c5 100644 --- a/sql/handler.cc +++ b/sql/handler.cc @@ -183,6 +183,23 @@ const char *ha_get_storage_engine(enum db_type db_type) return "none"; } +bool ha_check_storage_engine_flag(enum db_type db_type, uint32 flag) +{ + show_table_type_st *types; + for (types= sys_table_types; types->type; types++) + { + if (db_type == types->db_type) + { + if (types->ht->flags & flag) + return TRUE; + else + return FALSE; + } + } + + return FALSE; +} + my_bool ha_storage_engine_is_enabled(enum db_type database_type) { diff --git a/sql/handler.h b/sql/handler.h index 50f697bc980..9d955d1be58 100644 --- a/sql/handler.h +++ b/sql/handler.h @@ -377,8 +377,10 @@ struct show_table_alias_st { }; /* Possible flags of a handlerton */ -#define HTON_NO_FLAGS 0 -#define HTON_CLOSE_CURSORS_AT_COMMIT 1 +#define HTON_NO_FLAGS 0 +#define HTON_CLOSE_CURSORS_AT_COMMIT (1 << 0) +#define HTON_ALTER_NOT_SUPPORTED (1 << 1) +#define HTON_CAN_RECREATE (1 << 2) typedef struct st_thd_trans { @@ -848,18 +850,13 @@ extern ulong total_ha, total_ha_2pc; #define ha_commit(thd) (ha_commit_trans((thd), TRUE)) #define ha_rollback(thd) (ha_rollback_trans((thd), TRUE)) -#define ha_supports_generate(T) (T != DB_TYPE_INNODB && \ - T != DB_TYPE_BERKELEY_DB && \ - T != DB_TYPE_ARCHIVE_DB && \ - T != DB_TYPE_FEDERATED_DB && \ - T != DB_TYPE_NDBCLUSTER) - /* lookups */ enum db_type ha_resolve_by_name(const char *name, uint namelen); const char *ha_get_storage_engine(enum db_type db_type); handler *get_new_handler(TABLE *table, enum db_type db_type); enum db_type ha_checktype(THD *thd, enum db_type database_type, bool no_substitute, bool report_error); +bool ha_check_storage_engine_flag(enum db_type db_type, uint32 flag); /* basic stuff */ int ha_init(void); diff --git a/sql/sql_delete.cc b/sql/sql_delete.cc index 4001a51f459..d9734b7cae8 100644 --- a/sql/sql_delete.cc +++ b/sql/sql_delete.cc @@ -787,7 +787,7 @@ bool mysql_truncate(THD *thd, TABLE_LIST *table_list, bool dont_send_ok) TABLE *table= *table_ptr; table->file->info(HA_STATUS_AUTO | HA_STATUS_NO_LOCK); db_type table_type= table->s->db_type; - if (!ha_supports_generate(table_type)) + if (!ha_check_storage_engine_flag(table_type, HTON_CAN_RECREATE)) goto trunc_by_del; strmov(path, table->s->path); *table_ptr= table->next; // Unlink table from list @@ -818,7 +818,8 @@ bool mysql_truncate(THD *thd, TABLE_LIST *table_list, bool dont_send_ok) table_list->db, table_list->table_name); DBUG_RETURN(TRUE); } - if (!ha_supports_generate(table_type) || thd->lex->sphead) + if (!ha_check_storage_engine_flag(table_type, HTON_CAN_RECREATE) + || thd->lex->sphead) goto trunc_by_del; if (lock_and_wait_for_table_name(thd, table_list)) DBUG_RETURN(TRUE); diff --git a/sql/sql_table.cc b/sql/sql_table.cc index dba4168343a..4438400806f 100644 --- a/sql/sql_table.cc +++ b/sql/sql_table.cc @@ -3156,6 +3156,16 @@ bool mysql_alter_table(THD *thd,char *new_db, char *new_name, if (create_info->row_type == ROW_TYPE_NOT_USED) create_info->row_type= table->s->row_type; + DBUG_PRINT("info", ("old type: %d new type: %d", old_db_type, new_db_type)); + if (ha_check_storage_engine_flag(old_db_type, HTON_ALTER_NOT_SUPPORTED) + || ha_check_storage_engine_flag(new_db_type, HTON_ALTER_NOT_SUPPORTED)) + { + DBUG_PRINT("info", ("doesn't support alter")); + my_error(ER_ILLEGAL_HA, MYF(0), table_name); + DBUG_RETURN(TRUE); + } + DBUG_PRINT("info", ("supports alter")); + thd->proc_info="setup"; if (!(alter_info->flags & ~(ALTER_RENAME | ALTER_KEYS_ONOFF)) && !table->s->tmp_table) // no need to touch frm -- cgit v1.2.1