18 #include "sql_class.h"
19 #include "sql_table.h"
34 frm_type_enum dd_frm_type(THD *thd,
char *path,
enum legacy_db_type *dbt)
39 DBUG_ENTER(
"dd_frm_type");
41 *dbt= DB_TYPE_UNKNOWN;
43 if ((file=
mysql_file_open(key_file_frm, path, O_RDONLY | O_SHARE, MYF(0))) < 0)
44 DBUG_RETURN(FRMTYPE_ERROR);
45 error=
mysql_file_read(file, (uchar*) header,
sizeof(header), MYF(MY_NABP));
49 DBUG_RETURN(FRMTYPE_ERROR);
50 if (!strncmp((
char*) header,
"TYPE=VIEW\n",
sizeof(header)))
51 DBUG_RETURN(FRMTYPE_VIEW);
58 if (header[0] != (uchar) 254 || header[1] != 1 ||
59 (header[2] != FRM_VER && header[2] != FRM_VER+1 &&
60 (header[2] < FRM_VER+3 || header[2] > FRM_VER+4)))
61 DBUG_RETURN(FRMTYPE_TABLE);
63 *dbt= (
enum legacy_db_type) (uint) *(header + 3);
66 DBUG_RETURN(FRMTYPE_TABLE);
82 bool dd_frm_storage_engine(THD *thd,
const char *db,
const char *
table_name,
85 char path[FN_REFLEN + 1];
86 enum legacy_db_type db_type;
87 LEX_STRING db_name = {(
char *) db, strlen(db)};
90 DBUG_ASSERT(thd->mdl_context.is_lock_owner(MDL_key::TABLE, db,
91 table_name, MDL_SHARED));
93 if (check_and_convert_db_name(&db_name, FALSE) != IDENT_NAME_OK)
96 enum_ident_name_check ident_check_status=
97 check_table_name(table_name, strlen(table_name), FALSE);
98 if (ident_check_status == IDENT_NAME_WRONG)
100 my_error(ER_WRONG_TABLE_NAME, MYF(0), table_name);
103 else if (ident_check_status == IDENT_NAME_TOO_LONG)
105 my_error(ER_TOO_LONG_IDENT, MYF(0), table_name);
109 (void) build_table_filename(path,
sizeof(path) - 1, db,
112 dd_frm_type(thd, path, &db_type);
115 if (db_type == DB_TYPE_UNKNOWN ||
116 !(*table_type= ha_resolve_by_legacy_type(thd, db_type)))
118 my_error(ER_NO_SUCH_TABLE, MYF(0), db, table_name);
141 bool dd_check_storage_engine_flag(THD *thd,
142 const char *db,
const char *table_name,
143 uint32 flag,
bool *yes_no)
147 if (dd_frm_storage_engine(thd, db, table_name, &table_type))
150 *yes_no= ha_check_storage_engine_flag(table_type, flag);
167 bool dd_recreate_table(THD *thd,
const char *db,
const char *table_name)
171 char path[FN_REFLEN + 1];
172 DBUG_ENTER(
"dd_recreate_table");
175 DBUG_ASSERT(thd->mdl_context.is_lock_owner(MDL_key::TABLE, db, table_name,
178 memset(&create_info, 0,
sizeof(create_info));
181 build_table_filename(path,
sizeof(path) - 1, db, table_name,
"", 0);