MySQL Lists are EOL. Please join:

List:Internals« Previous MessageNext Message »
From:antony Date:June 17 2005 9:15pm
Subject:bk commit into 5.0 tree (acurtis:1.1962) BUG#6877
View as plain text  
Below is the list of changes that have just been committed into a local
5.0 repository of antony. When antony does a push these changes will
be propagated to the main repository and, within 24 hours after the
push, to the public repository.
For information on how to access the public repository
see http://dev.mysql.com/doc/mysql/en/installing-source-tree.html

ChangeSet
  1.1962 05/06/17 22:14:44 acurtis@stripped +12 -0
  Bug#6877 MySQL should give an error if the requested table type is not available
    Implement new SQL mode - NO_ENGINE_SUBSTITUTION

  sql/unireg.cc
    1.63 05/06/17 22:14:29 acurtis@stripped +1 -1
    change to create_frm() args

  sql/table.cc
    1.169 05/06/17 22:14:28 acurtis@stripped +6 -6
    change to ha_checktype(), create_frm(), get_table_type() args

  sql/sql_table.cc
    1.253 05/06/17 22:14:28 acurtis@stripped +29 -22
    move common code to check_engine()
    change to ha_checktype(), get_table_type() args

  sql/sql_rename.cc
    1.28 05/06/17 22:14:28 acurtis@stripped +1 -1
    change to get_table_type() args

  sql/sql_delete.cc
    1.152 05/06/17 22:14:28 acurtis@stripped +1 -1
    change to get_table_type() args

  sql/set_var.cc
    1.119 05/06/17 22:14:28 acurtis@stripped +1 -1
    change to ha_checktype() args

  sql/mysqld.cc
    1.471 05/06/17 22:14:27 acurtis@stripped +1 -0
    new sql mode NO_ENGINE_SUBSTITUTION

  sql/mysql_priv.h
    1.316 05/06/17 22:14:27 acurtis@stripped +3 -2
    new sql mode NO_ENGINE_SUBSTITUTION
    change to args for get_table_type() and create_frm()

  sql/handler.h
    1.143 05/06/17 22:14:27 acurtis@stripped +2 -1
    change to ha_checktype()

  sql/handler.cc
    1.175 05/06/17 22:14:27 acurtis@stripped +12 -3
    change to ha_checktype()

  mysql-test/t/sql_mode.test
    1.11 05/06/17 22:14:27 acurtis@stripped +20 -0
    Test for bug 6877

  mysql-test/r/sql_mode.result
    1.20 05/06/17 22:14:27 acurtis@stripped +18 -0
    Test for bug 6877

# This is a BitKeeper patch.  What follows are the unified diffs for the
# set of deltas contained in the patch.  The rest of the patch, the part
# that BitKeeper cares about, is below these diffs.
# User:	acurtis
# Host:	ltantony.xiphis.org
# Root:	/usr/home/antony/work2/p3-bug6877.3

--- 1.174/sql/handler.cc	2005-06-07 11:54:41 +01:00
+++ 1.175/sql/handler.cc	2005-06-17 22:14:27 +01:00
@@ -165,12 +165,22 @@
 
 	/* Use other database handler if databasehandler is not incompiled */
 
-enum db_type ha_checktype(enum db_type database_type)
+enum db_type ha_checktype(THD *thd, enum db_type database_type,
+                          bool no_substitute, bool report_error)
 {
-  THD *thd;
   if (ha_storage_engine_is_enabled(database_type))
     return database_type;
 
+  if (no_substitute)
+  {
+    if (report_error)
+    {
+      const char *engine_name= ha_get_storage_engine(database_type);
+      my_error(ER_FEATURE_DISABLED,MYF(0),engine_name,engine_name);
+    }
+    return DB_TYPE_UNKNOWN;
+  }
+
   switch (database_type) {
 #ifndef NO_HASH
   case DB_TYPE_HASH:
@@ -182,7 +192,6 @@
     break;
   }
   
-  thd= current_thd;
   return ((enum db_type) thd->variables.table_type != DB_TYPE_UNKNOWN ?
           (enum db_type) thd->variables.table_type :
           ((enum db_type) global_system_variables.table_type !=

--- 1.142/sql/handler.h	2005-05-18 21:54:33 +01:00
+++ 1.143/sql/handler.h	2005-06-17 22:14:27 +01:00
@@ -813,7 +813,8 @@
 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(enum db_type database_type);
+enum db_type ha_checktype(THD *thd, enum db_type database_type,
+                          bool no_substitute, bool report_error);
 
 /* basic stuff */
 int ha_init(void);

--- 1.315/sql/mysql_priv.h	2005-06-16 22:58:25 +01:00
+++ 1.316/sql/mysql_priv.h	2005-06-17 22:14:27 +01:00
@@ -325,6 +325,7 @@
 #define MODE_TRADITIONAL		(MODE_ERROR_FOR_DIVISION_BY_ZERO*2)
 #define MODE_NO_AUTO_CREATE_USER	(MODE_TRADITIONAL*2)
 #define MODE_HIGH_NOT_PRECEDENCE	(MODE_NO_AUTO_CREATE_USER*2)
+#define MODE_NO_ENGINE_SUBSTITUTION     (MODE_HIGH_NOT_PRECEDENCE*2)
 /*
   Replication uses 8 bytes to store SQL_MODE in the binary log. The day you
   use strictly more than 64 bits by adding one more define above, you should
@@ -1232,7 +1233,7 @@
 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(const char *name);
+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);
@@ -1289,7 +1290,7 @@
 		     const char *newname);
 ulong next_io_size(ulong pos);
 void append_unescaped(String *res, const char *pos, uint length);
-int create_frm(char *name,uint reclength,uchar *fileinfo,
+int create_frm(THD *thd, char *name,uint reclength,uchar *fileinfo,
 	       HA_CREATE_INFO *create_info, uint keys);
 void update_create_info_from_table(HA_CREATE_INFO *info, TABLE *form);
 int rename_file_ext(const char * from,const char * to,const char * ext);

--- 1.470/sql/mysqld.cc	2005-06-16 22:58:25 +01:00
+++ 1.471/sql/mysqld.cc	2005-06-17 22:14:27 +01:00
@@ -229,6 +229,7 @@
   "NO_AUTO_VALUE_ON_ZERO", "NO_BACKSLASH_ESCAPES", "STRICT_TRANS_TABLES", "STRICT_ALL_TABLES",
   "NO_ZERO_IN_DATE", "NO_ZERO_DATE", "ALLOW_INVALID_DATES", "ERROR_FOR_DIVISION_BY_ZERO",
   "TRADITIONAL", "NO_AUTO_CREATE_USER", "HIGH_NOT_PRECEDENCE",
+  "NO_ENGINE_SUBSTITUTION",
   NullS
 };
 TYPELIB sql_mode_typelib= { array_elements(sql_mode_names)-1,"",

--- 1.151/sql/sql_delete.cc	2005-05-31 10:29:22 +01:00
+++ 1.152/sql/sql_delete.cc	2005-06-17 22:14:28 +01:00
@@ -790,7 +790,7 @@
   if (!dont_send_ok)
   {
     db_type table_type;
-    if ((table_type=get_table_type(path)) == DB_TYPE_UNKNOWN)
+    if ((table_type=get_table_type(thd, path)) == DB_TYPE_UNKNOWN)
     {
       my_error(ER_NO_SUCH_TABLE, MYF(0),
                table_list->db, table_list->table_name);

--- 1.252/sql/sql_table.cc	2005-06-10 03:29:52 +01:00
+++ 1.253/sql/sql_table.cc	2005-06-17 22:14:28 +01:00
@@ -39,6 +39,8 @@
 				    uint order_num, ORDER *order,
 				    ha_rows *copied,ha_rows *deleted);
 static bool prepare_blob_field(THD *thd, create_field *sql_field);
+static bool check_engine(THD *thd, const char *table_name,
+                         enum db_type *new_engine);                             
 
 
 /*
@@ -268,7 +270,7 @@
     else
     {
       char *end;
-      db_type table_type= get_table_type(path);
+      db_type table_type= get_table_type(thd, path);
       *(end=fn_ext(path))=0;			// Remove extension for delete
       error= ha_delete_table(thd, table_type, path, table->table_name,
                              !dont_log_query);
@@ -1490,7 +1492,6 @@
   KEY		*key_info_buffer;
   handler	*file;
   bool		error= TRUE;
-  enum db_type	new_db_type;
   DBUG_ENTER("mysql_create_table");
 
   /* Check for duplicate fields and check type of table to create */
@@ -1500,16 +1501,8 @@
                MYF(0));
     DBUG_RETURN(TRUE);
   }
-  if ((new_db_type= ha_checktype(create_info->db_type)) !=
-      create_info->db_type)
-  {
-    create_info->db_type= new_db_type;
-    push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_WARN,
-			ER_WARN_USING_OTHER_HANDLER,
-			ER(ER_WARN_USING_OTHER_HANDLER),
-			ha_get_storage_engine(new_db_type),
-			table_name);
-  }
+  if (check_engine(thd, table_name, &create_info->db_type))
+    DBUG_RETURN(TRUE);
   db_options= create_info->table_options;
   if (create_info->row_type == ROW_TYPE_DYNAMIC)
     db_options|=HA_OPTION_PACK_RECORD;
@@ -3125,16 +3118,9 @@
   old_db_type= table->s->db_type;
   if (create_info->db_type == DB_TYPE_DEFAULT)
     create_info->db_type= old_db_type;
-  if ((new_db_type= ha_checktype(create_info->db_type)) !=
-      create_info->db_type)
-  {
-    create_info->db_type= new_db_type;
-    push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_WARN,
-			ER_WARN_USING_OTHER_HANDLER,
-			ER(ER_WARN_USING_OTHER_HANDLER),
-			ha_get_storage_engine(new_db_type),
-			new_name);
-  }
+  if (check_engine(thd, new_name, &create_info->db_type))
+    DBUG_RETURN(TRUE);
+  new_db_type= create_info->db_type;
   if (create_info->row_type == ROW_TYPE_NOT_USED)
     create_info->row_type= table->s->row_type;
 
@@ -4131,4 +4117,25 @@
   if (table)
     table->table=0;
   DBUG_RETURN(TRUE);
+}
+
+static bool check_engine(THD *thd, const char *table_name,
+                         enum db_type *new_engine)
+{
+  enum db_type req_engine= *new_engine;
+  bool no_substitution= 
+        test(thd->variables.sql_mode & MODE_NO_ENGINE_SUBSTITUTION);
+  if ((*new_engine= 
+       ha_checktype(thd, req_engine, no_substitution, 1)) == DB_TYPE_UNKNOWN)
+    return TRUE;
+
+  if (req_engine != *new_engine)
+  {
+    push_warning_printf(thd, MYSQL_ERROR::WARN_LEVEL_WARN,
+                       ER_WARN_USING_OTHER_HANDLER,
+                       ER(ER_WARN_USING_OTHER_HANDLER),
+                       ha_get_storage_engine(*new_engine),
+                       table_name);
+  }
+  return FALSE;
 }

--- 1.168/sql/table.cc	2005-06-01 14:35:04 +01:00
+++ 1.169/sql/table.cc	2005-06-17 22:14:28 +01:00
@@ -163,7 +163,7 @@
   if (share->frm_version == FRM_VER_TRUE_VARCHAR -1 && head[33] == 5)
     share->frm_version= FRM_VER_TRUE_VARCHAR;
 
-  share->db_type= ha_checktype((enum db_type) (uint) *(head+3));
+  share->db_type= ha_checktype(thd,(enum db_type) (uint) *(head+3),0,0);
   share->db_create_options= db_create_options=uint2korr(head+30);
   share->db_options_in_use= share->db_create_options;
   share->mysql_version= uint4korr(head+51);
@@ -1341,8 +1341,8 @@
 
 	/* Create a .frm file */
 
-File create_frm(register my_string name, uint reclength, uchar *fileinfo,
-		HA_CREATE_INFO *create_info, uint keys)
+File create_frm(THD *thd, register my_string name, uint reclength,
+		uchar *fileinfo, HA_CREATE_INFO *create_info, uint keys)
 {
   register File file;
   ulong length;
@@ -1375,7 +1375,7 @@
     fileinfo[1]= 1;
     fileinfo[2]= FRM_VER+3+ test(create_info->varchar);
 
-    fileinfo[3]= (uchar) ha_checktype(create_info->db_type);
+    fileinfo[3]= (uchar) ha_checktype(thd,create_info->db_type,0,0);
     fileinfo[4]=1;
     int2store(fileinfo+6,IO_SIZE);		/* Next block starts here */
     key_length=keys*(7+NAME_LEN+MAX_REF_PARTS*9)+16;
@@ -1637,7 +1637,7 @@
 ** Get type of table from .frm file
 */
 
-db_type get_table_type(const char *name)
+db_type get_table_type(THD *thd, const char *name)
 {
   File	 file;
   uchar head[4];
@@ -1653,7 +1653,7 @@
       (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((enum db_type) (uint) *(head+3)));
+  DBUG_RETURN(ha_checktype(thd,(enum db_type) (uint) *(head+3),0,0));
 }
 
 

--- 1.62/sql/unireg.cc	2005-06-06 14:00:17 +01:00
+++ 1.63/sql/unireg.cc	2005-06-17 22:14:29 +01:00
@@ -113,7 +113,7 @@
   }
   reclength=uint2korr(forminfo+266);
 
-  if ((file=create_frm(file_name, reclength, fileinfo,
+  if ((file=create_frm(thd, file_name, reclength, fileinfo,
 		       create_info, keys)) < 0)
   {
     my_free((gptr) screen_buff,MYF(0));

--- 1.19/mysql-test/r/sql_mode.result	2005-06-09 17:03:12 +01:00
+++ 1.20/mysql-test/r/sql_mode.result	2005-06-17 22:14:27 +01:00
@@ -402,4 +402,22 @@
 SELECT "a\\b", "a\\\'b", "a""\\b", "a""\\\'b";
 a\b	a\'b	a"\b	a"\'b
 a\b	a\'b	a"\b	a"\'b
+set session sql_mode = 'NO_ENGINE_SUBSTITUTION';
+create table t1 (a int) engine=isam;
+ERROR HY000: The 'ISAM' feature is disabled; you need MySQL built with 'ISAM' to have it working
+show create table t1;
+ERROR 42S02: Table 'test.t1' doesn't exist
+drop table if exists t1;
+Warnings:
+Note	1051	Unknown table 't1'
+set session sql_mode = '';
+create table t1 (a int) engine=isam;
+Warnings:
+Warning	1266	Using storage engine MyISAM for table 't1'
+show create table t1;
+Table	Create Table
+t1	CREATE TABLE `t1` (
+  `a` int(11) default NULL
+) ENGINE=MyISAM DEFAULT CHARSET=latin1
+drop table t1;
 SET @@SQL_MODE=@OLD_SQL_MODE;

--- 1.10/mysql-test/t/sql_mode.test	2005-06-09 17:03:35 +01:00
+++ 1.11/mysql-test/t/sql_mode.test	2005-06-17 22:14:27 +01:00
@@ -189,4 +189,24 @@
 SELECT 'a\\b', 'a\\\"b', 'a''\\b', 'a''\\\"b';
 SELECT "a\\b", "a\\\'b", "a""\\b", "a""\\\'b";
 
+
+#
+# Bug#6877: MySQL should give an error if the requested table type 
+#           is not available
+#
+
+set session sql_mode = 'NO_ENGINE_SUBSTITUTION';
+--error 1289
+create table t1 (a int) engine=isam;
+--error 1146
+show create table t1;
+drop table if exists t1;
+
+# for comparison, lets see the warnings...
+set session sql_mode = '';
+create table t1 (a int) engine=isam;
+show create table t1;
+drop table t1;
+
+
 SET @@SQL_MODE=@OLD_SQL_MODE;

--- 1.27/sql/sql_rename.cc	2005-03-16 14:10:55 +00:00
+++ 1.28/sql/sql_rename.cc	2005-06-17 22:14:28 +01:00
@@ -164,7 +164,7 @@
 	    ren_table->db, old_alias,
 	    reg_ext);
     unpack_filename(name, name);
-    if ((table_type=get_table_type(name)) == DB_TYPE_UNKNOWN)
+    if ((table_type=get_table_type(thd, name)) == DB_TYPE_UNKNOWN)
     {
       my_error(ER_FILE_NOT_FOUND, MYF(0), name, my_errno);
       if (!skip_error)

--- 1.118/sql/set_var.cc	2005-06-09 17:01:46 +01:00
+++ 1.119/sql/set_var.cc	2005-06-17 22:14:28 +01:00
@@ -3131,7 +3131,7 @@
     if (!(res=var->value->val_str(&str)) ||
 	!(var->save_result.ulong_value=
           (ulong) (db_type= ha_resolve_by_name(res->ptr(), res->length()))) ||
-        ha_checktype(db_type) != db_type)
+        ha_checktype(thd, db_type, 1, 0) != db_type)
     {
       value= res ? res->c_ptr() : "NULL";
       goto err;
Thread
bk commit into 5.0 tree (acurtis:1.1962) BUG#6877antony17 Jun