summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorunknown <jani@ua141d10.elisa.omakaista.fi>2005-11-03 16:10:11 +0200
committerunknown <jani@ua141d10.elisa.omakaista.fi>2005-11-03 16:10:11 +0200
commit5af7ca80d98459b9c163328eaf8709abdf8c9883 (patch)
tree533bc3410929cad9d7bedd3ecdd6edd46725efa1
parentabd77bc56397c1522f2b729334f877f9806dafd2 (diff)
downloadmariadb-git-5af7ca80d98459b9c163328eaf8709abdf8c9883.tar.gz
Changes in get_table_type() and mysql_frm_type(). The main problem was
that in mysql_rm_table_part2_with_lock() previously we needed to open same file twice. Now once is enough. sql/mysql_priv.h: Merged functions get_table_type() and mysql_frm_type() into one, using the name from latter one. sql/sql_base.cc: Changed get_table_type() to mysql_frm_type() sql/sql_delete.cc: Changed get_table_type() to mysql_frm_type() sql/sql_rename.cc: Changed get_table_type() to mysql_frm_type() sql/sql_show.cc: Changed get_table_type() to mysql_frm_type() sql/sql_table.cc: Changed get_table_type() to mysql_frm_type() sql/sql_view.cc: Merged code from get_table_type() and mysql_frm_type() into the latter one. sql/sql_view.h: Function prototype changes. sql/table.cc: No longer needed.
-rw-r--r--sql/mysql_priv.h1
-rw-r--r--sql/sql_base.cc3
-rw-r--r--sql/sql_delete.cc3
-rw-r--r--sql/sql_rename.cc7
-rw-r--r--sql/sql_show.cc3
-rw-r--r--sql/sql_table.cc13
-rw-r--r--sql/sql_view.cc34
-rw-r--r--sql/sql_view.h2
-rw-r--r--sql/table.cc23
9 files changed, 45 insertions, 44 deletions
diff --git a/sql/mysql_priv.h b/sql/mysql_priv.h
index e33ac05e293..abf44c98977 100644
--- a/sql/mysql_priv.h
+++ b/sql/mysql_priv.h
@@ -1295,7 +1295,6 @@ int openfrm(THD *thd, const char *name,const char *alias,uint filestat,
int readfrm(const char *name, const void** data, uint* length);
int writefrm(const char* name, const void* data, uint len);
int closefrm(TABLE *table);
-db_type get_table_type(THD *thd, const char *name);
int read_string(File file, gptr *to, uint length);
void free_blobs(TABLE *table);
int set_zone(int nr,int min_zone,int max_zone);
diff --git a/sql/sql_base.cc b/sql/sql_base.cc
index 973fbca12f5..b3072205514 100644
--- a/sql/sql_base.cc
+++ b/sql/sql_base.cc
@@ -1193,10 +1193,11 @@ TABLE *open_table(THD *thd, TABLE_LIST *table_list, MEM_ROOT *mem_root,
*/
{
char path[FN_REFLEN];
+ db_type not_used;
strxnmov(path, FN_REFLEN, mysql_data_home, "/", table_list->db, "/",
table_list->table_name, reg_ext, NullS);
(void) unpack_filename(path, path);
- if (mysql_frm_type(path) == FRMTYPE_VIEW)
+ if (mysql_frm_type(thd, path, &not_used) == FRMTYPE_VIEW)
{
TABLE tab;// will not be used (because it's VIEW) but have to be passed
table= &tab;
diff --git a/sql/sql_delete.cc b/sql/sql_delete.cc
index 83f50ba3ac5..429db7cbf49 100644
--- a/sql/sql_delete.cc
+++ b/sql/sql_delete.cc
@@ -830,7 +830,8 @@ bool mysql_truncate(THD *thd, TABLE_LIST *table_list, bool dont_send_ok)
if (!dont_send_ok)
{
db_type table_type;
- if ((table_type=get_table_type(thd, path)) == DB_TYPE_UNKNOWN)
+ mysql_frm_type(thd, path, &table_type);
+ if (table_type == DB_TYPE_UNKNOWN)
{
my_error(ER_NO_SUCH_TABLE, MYF(0),
table_list->db, table_list->table_name);
diff --git a/sql/sql_rename.cc b/sql/sql_rename.cc
index 154e828b47e..80fcb973028 100644
--- a/sql/sql_rename.cc
+++ b/sql/sql_rename.cc
@@ -134,6 +134,8 @@ rename_tables(THD *thd, TABLE_LIST *table_list, bool skip_error)
{
TABLE_LIST *ren_table,*new_table;
frm_type_enum frm_type;
+ db_type table_type;
+
DBUG_ENTER("rename_tables");
for (ren_table= table_list; ren_table; ren_table= new_table->next_local)
@@ -166,13 +168,12 @@ rename_tables(THD *thd, TABLE_LIST *table_list, bool skip_error)
reg_ext);
unpack_filename(name, name);
- frm_type= mysql_frm_type(name);
+ frm_type= mysql_frm_type(thd, name, &table_type);
switch (frm_type)
{
case FRMTYPE_TABLE:
{
- db_type table_type;
- if ((table_type= get_table_type(thd, name)) == DB_TYPE_UNKNOWN)
+ if (table_type == DB_TYPE_UNKNOWN)
my_error(ER_FILE_NOT_FOUND, MYF(0), name, my_errno);
else
rc= mysql_rename_table(table_type, ren_table->db, old_alias,
diff --git a/sql/sql_show.cc b/sql/sql_show.cc
index 69b824f8cd9..1fa4e3f9b48 100644
--- a/sql/sql_show.cc
+++ b/sql/sql_show.cc
@@ -2003,6 +2003,7 @@ int get_all_tables(THD *thd, TABLE_LIST *tables, COND *cond)
Security_context *sctx= thd->security_ctx;
uint derived_tables= lex->derived_tables;
int error= 1;
+ db_type not_used;
Open_tables_state open_tables_state_backup;
DBUG_ENTER("get_all_tables");
@@ -2114,7 +2115,7 @@ int get_all_tables(THD *thd, TABLE_LIST *tables, COND *cond)
else
{
my_snprintf(end, len, "/%s%s", file_name, reg_ext);
- switch (mysql_frm_type(path)) {
+ switch (mysql_frm_type(thd, path, &not_used)) {
case FRMTYPE_ERROR:
table->field[3]->store("ERROR", 5, system_charset_info);
break;
diff --git a/sql/sql_table.cc b/sql/sql_table.cc
index 1e96891113b..6861a29b4d2 100644
--- a/sql/sql_table.cc
+++ b/sql/sql_table.cc
@@ -218,6 +218,7 @@ int mysql_rm_table_part2(THD *thd, TABLE_LIST *tables, bool if_exists,
String wrong_tables;
int error;
bool some_tables_deleted=0, tmp_table_deleted=0, foreign_key_error=0;
+
DBUG_ENTER("mysql_rm_table_part2");
if (lock_table_names(thd, tables))
@@ -229,6 +230,8 @@ int mysql_rm_table_part2(THD *thd, TABLE_LIST *tables, bool if_exists,
for (table= tables; table; table= table->next_local)
{
char *db=table->db;
+ db_type table_type= DB_TYPE_UNKNOWN;
+
mysql_ha_flush(thd, table, MYSQL_HA_CLOSE_FINAL);
if (!close_temporary_table(thd, db, table->table_name))
{
@@ -256,7 +259,8 @@ int mysql_rm_table_part2(THD *thd, TABLE_LIST *tables, bool if_exists,
if (drop_temporary ||
(access(path,F_OK) &&
ha_create_table_from_engine(thd,db,alias)) ||
- (!drop_view && mysql_frm_type(path) != FRMTYPE_TABLE))
+ (!drop_view &&
+ mysql_frm_type(thd, path, &table_type) != FRMTYPE_TABLE))
{
// Table was not found on disk and table can't be created from engine
if (if_exists)
@@ -269,7 +273,8 @@ int mysql_rm_table_part2(THD *thd, TABLE_LIST *tables, bool if_exists,
else
{
char *end;
- db_type table_type= get_table_type(thd, path);
+ if (table_type == DB_TYPE_UNKNOWN)
+ mysql_frm_type(thd, path, &table_type);
*(end=fn_ext(path))=0; // Remove extension for delete
error= ha_delete_table(thd, table_type, path, table->table_name,
!dont_log_query);
@@ -2611,6 +2616,8 @@ bool mysql_create_like_table(THD* thd, TABLE_LIST* table,
char *src_table= table_ident->table.str;
int err;
bool res= TRUE;
+ db_type not_used;
+
TABLE_LIST src_tables_list;
DBUG_ENTER("mysql_create_like_table");
src_db= table_ident->db.str ? table_ident->db.str : thd->db;
@@ -2658,7 +2665,7 @@ bool mysql_create_like_table(THD* thd, TABLE_LIST* table,
/*
create like should be not allowed for Views, Triggers, ...
*/
- if (mysql_frm_type(src_path) != FRMTYPE_TABLE)
+ if (mysql_frm_type(thd, src_path, &not_used) != FRMTYPE_TABLE)
{
my_error(ER_WRONG_OBJECT, MYF(0), src_db, src_table, "BASE TABLE");
goto err;
diff --git a/sql/sql_view.cc b/sql/sql_view.cc
index 858f0c2520e..42b1aa3c196 100644
--- a/sql/sql_view.cc
+++ b/sql/sql_view.cc
@@ -1110,6 +1110,7 @@ bool mysql_drop_view(THD *thd, TABLE_LIST *views, enum_drop_mode drop_mode)
char path[FN_REFLEN];
TABLE_LIST *view;
bool type= 0;
+ db_type not_used;
for (view= views; view; view= view->next_local)
{
@@ -1117,7 +1118,8 @@ bool mysql_drop_view(THD *thd, TABLE_LIST *views, enum_drop_mode drop_mode)
view->table_name, reg_ext, NullS);
(void) unpack_filename(path, path);
VOID(pthread_mutex_lock(&LOCK_open));
- if (access(path, F_OK) || (type= (mysql_frm_type(path) != FRMTYPE_VIEW)))
+ if (access(path, F_OK) ||
+ (type= (mysql_frm_type(thd, path, &not_used) != FRMTYPE_VIEW)))
{
char name[FN_REFLEN];
my_snprintf(name, sizeof(name), "%s.%s", view->db, view->table_name);
@@ -1164,24 +1166,36 @@ err:
FRMTYPE_VIEW view
*/
-frm_type_enum mysql_frm_type(char *path)
+frm_type_enum mysql_frm_type(THD *thd, char *path, db_type *dbt)
{
File file;
- char header[10]; //"TYPE=VIEW\n" it is 10 characters
- int length;
+ uchar header[10]; //"TYPE=VIEW\n" it is 10 characters
+ int error;
DBUG_ENTER("mysql_frm_type");
+ *dbt= DB_TYPE_UNKNOWN;
+
if ((file= my_open(path, O_RDONLY | O_SHARE, MYF(0))) < 0)
- {
DBUG_RETURN(FRMTYPE_ERROR);
- }
- length= my_read(file, (byte*) header, sizeof(header), MYF(MY_WME));
+ error= my_read(file, (byte*) header, sizeof(header), MYF(MY_WME | MY_NABP));
my_close(file, MYF(MY_WME));
- if (length == (int) MY_FILE_ERROR)
+
+ if (error)
DBUG_RETURN(FRMTYPE_ERROR);
- if (length < (int) sizeof(header) ||
- !strncmp(header, "TYPE=VIEW\n", sizeof(header)))
+ if (!strncmp((char*) header, "TYPE=VIEW\n", sizeof(header)))
DBUG_RETURN(FRMTYPE_VIEW);
+
+ /*
+ This is just a check for DB_TYPE. We'll return default unknown type
+ 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)))
+ DBUG_RETURN(FRMTYPE_TABLE);
+
+ *dbt= ha_checktype(thd, (enum db_type) (uint) *(header + 3), 0, 0);
DBUG_RETURN(FRMTYPE_TABLE); // Is probably a .frm table
}
diff --git a/sql/sql_view.h b/sql/sql_view.h
index 4cc9eb454fb..4e3d50655e2 100644
--- a/sql/sql_view.h
+++ b/sql/sql_view.h
@@ -27,7 +27,7 @@ bool check_key_in_view(THD *thd, TABLE_LIST * view);
bool insert_view_fields(THD *thd, List<Item> *list, TABLE_LIST *view);
-frm_type_enum mysql_frm_type(char *path);
+frm_type_enum mysql_frm_type(THD *thd, char *path, db_type *dbt);
int view_checksum(THD *thd, TABLE_LIST *view);
diff --git a/sql/table.cc b/sql/table.cc
index 722e4e4df25..777d8672ab3 100644
--- a/sql/table.cc
+++ b/sql/table.cc
@@ -1693,29 +1693,6 @@ bool check_column_name(const char *name)
}
/*
-** Get type of table from .frm file
-*/
-
-db_type get_table_type(THD *thd, const char *name)
-{
- File file;
- uchar head[4];
- int error;
- DBUG_ENTER("get_table_type");
- DBUG_PRINT("enter",("name: '%s'",name));
-
- if ((file=my_open(name,O_RDONLY, MYF(0))) < 0)
- DBUG_RETURN(DB_TYPE_UNKNOWN);
- error=my_read(file,(byte*) head,4,MYF(MY_NABP));
- my_close(file,MYF(0));
- if (error || head[0] != (uchar) 254 || head[1] != 1 ||
- (head[2] != FRM_VER && head[2] != FRM_VER+1 &&
- (head[2] < FRM_VER+3 || head[2] > FRM_VER+4)))
- DBUG_RETURN(DB_TYPE_UNKNOWN);
- DBUG_RETURN(ha_checktype(thd,(enum db_type) (uint) *(head+3),0,0));
-}
-
-/*
Create Item_field for each column in the table.
SYNPOSIS