summaryrefslogtreecommitdiff
path: root/sql/datadict.cc
diff options
context:
space:
mode:
Diffstat (limited to 'sql/datadict.cc')
-rw-r--r--sql/datadict.cc118
1 files changed, 24 insertions, 94 deletions
diff --git a/sql/datadict.cc b/sql/datadict.cc
index e3f679cc7ec..4bc74af7bdb 100644
--- a/sql/datadict.cc
+++ b/sql/datadict.cc
@@ -55,11 +55,14 @@ frm_type_enum dd_frm_type(THD *thd, char *path, enum legacy_db_type *dbt)
if the following test is true (arg #3). This should not have effect
on return value from this function (default FRMTYPE_TABLE)
*/
- if (header[0] != (uchar) 254 || header[1] != 1 ||
- (header[2] != FRM_VER && header[2] != FRM_VER+1 &&
- (header[2] < FRM_VER+3 || header[2] > FRM_VER+4)))
+ if (!is_binary_frm_header(header))
DBUG_RETURN(FRMTYPE_TABLE);
+ /*
+ XXX this is a bug.
+ if header[3] is > DB_TYPE_FIRST_DYNAMIC, then the complete
+ storage engine name must be read from the frm
+ */
*dbt= (enum legacy_db_type) (uint) *(header + 3);
/* Probably a table. */
@@ -67,117 +70,44 @@ frm_type_enum dd_frm_type(THD *thd, char *path, enum legacy_db_type *dbt)
}
-/**
- Given a table name, check type of .frm and legacy table type.
-
- @param[in] thd The current session.
- @param[in] db Table schema.
- @param[in] table_name Table database.
- @param[out] table_type handlerton of the table if FRMTYPE_TABLE,
- otherwise undefined.
-
- @return FALSE if FRMTYPE_TABLE and storage engine found. TRUE otherwise.
-*/
-
-bool dd_frm_storage_engine(THD *thd, const char *db, const char *table_name,
- handlerton **table_type)
-{
- char path[FN_REFLEN + 1];
- enum legacy_db_type db_type;
- LEX_STRING db_name = {(char *) db, strlen(db)};
-
- /* There should be at least some lock on the table. */
- DBUG_ASSERT(thd->mdl_context.is_lock_owner(MDL_key::TABLE, db,
- table_name, MDL_SHARED));
-
- if (check_db_name(&db_name))
- {
- my_error(ER_WRONG_DB_NAME, MYF(0), db_name.str);
- return TRUE;
- }
-
- if (check_table_name(table_name, strlen(table_name), FALSE))
- {
- my_error(ER_WRONG_TABLE_NAME, MYF(0), table_name);
- return TRUE;
- }
-
- (void) build_table_filename(path, sizeof(path) - 1, db,
- table_name, reg_ext, 0);
-
- dd_frm_type(thd, path, &db_type);
-
- /* Type is unknown if the object is not found or is not a table. */
- if (db_type == DB_TYPE_UNKNOWN ||
- !(*table_type= ha_resolve_by_legacy_type(thd, db_type)))
- {
- my_error(ER_NO_SUCH_TABLE, MYF(0), db, table_name);
- return TRUE;
- }
-
- return FALSE;
-}
-
-
-/**
- Given a table name, check if the storage engine for the
- table referred by this name supports an option 'flag'.
- Return an error if the table does not exist or is not a
- base table.
-
- @pre Any metadata lock on the table.
-
- @param[in] thd The current session.
- @param[in] db Table schema.
- @param[in] table_name Table database.
- @param[in] flag The option to check.
- @param[out] yes_no The result. Undefined if error.
-*/
-
-bool dd_check_storage_engine_flag(THD *thd,
- const char *db, const char *table_name,
- uint32 flag, bool *yes_no)
-{
- handlerton *table_type;
-
- if (dd_frm_storage_engine(thd, db, table_name, &table_type))
- return TRUE;
-
- *yes_no= ha_check_storage_engine_flag(table_type, flag);
-
- return FALSE;
-}
-
-
/*
Regenerate a metadata locked table.
@param thd Thread context.
@param db Name of the database to which the table belongs to.
@param name Table name.
+ @param path For temporary tables only - path to table files.
+ Otherwise NULL (the path is calculated from db and table names).
@retval FALSE Success.
@retval TRUE Error.
*/
-bool dd_recreate_table(THD *thd, const char *db, const char *table_name)
+bool dd_recreate_table(THD *thd, const char *db, const char *table_name,
+ const char *path)
{
bool error= TRUE;
HA_CREATE_INFO create_info;
- char path[FN_REFLEN + 1];
+ char path_buf[FN_REFLEN + 1];
DBUG_ENTER("dd_recreate_table");
- /* There should be a exclusive metadata lock on the table. */
- DBUG_ASSERT(thd->mdl_context.is_lock_owner(MDL_key::TABLE, db, table_name,
- MDL_EXCLUSIVE));
-
memset(&create_info, 0, sizeof(create_info));
- /* Create a path to the table, but without a extension. */
- build_table_filename(path, sizeof(path) - 1, db, table_name, "", 0);
+ if (path)
+ create_info.options|= HA_LEX_CREATE_TMP_TABLE;
+ else
+ {
+ build_table_filename(path_buf, sizeof(path_buf) - 1,
+ db, table_name, "", 0);
+ path= path_buf;
+
+ /* There should be a exclusive metadata lock on the table. */
+ DBUG_ASSERT(thd->mdl_context.is_lock_owner(MDL_key::TABLE, db, table_name,
+ MDL_EXCLUSIVE));
+ }
/* Attempt to reconstruct the table. */
- error= ha_create_table(thd, path, db, table_name, &create_info, TRUE);
+ error= ha_create_table(thd, path, db, table_name, &create_info, NULL);
DBUG_RETURN(error);
}