MySQL Lists are EOL. Please join:

List:Internals« Previous MessageNext Message »
From:antony Date:June 6 2005 4:33pm
Subject:bk commit into 4.1 tree (acurtis:1.2316) BUG#6877
View as plain text  
Below is the list of changes that have just been committed into a local
4.1 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.2316 05/06/06 17:33:32 acurtis@stripped +9 -0
  Bug#6877 MySQL should give an error if the requested table type is not available
    implement new sql_mode NO_ENGINE_SUBSTITUTION

  sql/table.cc
    1.130 05/06/06 17:33:19 acurtis@stripped +3 -3
    ha_checktype() argument changes

  sql/sql_table.cc
    1.288 05/06/06 17:33:19 acurtis@stripped +29 -22
    refactor code to eliminate duplication

  sql/set_var.cc
    1.170 05/06/06 17:33:19 acurtis@stripped +1 -1
    ha_checktype() argument changes

  sql/mysqld.cc
    1.574 05/06/06 17:33:18 acurtis@stripped +1 -1
    New sql_mode - NO_ENGINE_SUBSTITUTION

  sql/mysql_priv.h
    1.351 05/06/06 17:33:18 acurtis@stripped +1 -0
    New sql_mode - NO_ENGINE_SUBSTITUTION

  sql/handler.h
    1.141 05/06/06 17:33:18 acurtis@stripped +2 -1
    change in ha_checktype() arguments

  sql/handler.cc
    1.168 05/06/06 17:33:17 acurtis@stripped +12 -1
    change in ha_checktype() arguments

  mysql-test/t/sql_mode.test
    1.8 05/06/06 17:33:17 acurtis@stripped +18 -0
    Test for new feature

  mysql-test/r/sql_mode.result
    1.11 05/06/06 17:33:17 acurtis@stripped +18 -0
    Test for new feature

# 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
# Root:	/usr/home/antony/work2/p3-bug6877.2

--- 1.167/sql/handler.cc	2005-06-05 18:38:39 +01:00
+++ 1.168/sql/handler.cc	2005-06-06 17:33:17 +01:00
@@ -161,10 +161,21 @@
 
 	/* Use other database handler if databasehandler is not incompiled */
 
-enum db_type ha_checktype(enum db_type database_type)
+enum db_type ha_checktype(enum db_type database_type, bool no_substitute,
+                          bool report_error)
 {
   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

--- 1.140/sql/handler.h	2005-05-18 18:40:35 +01:00
+++ 1.141/sql/handler.h	2005-06-06 17:33:18 +01:00
@@ -543,7 +543,8 @@
 int ha_init(void);
 int ha_panic(enum ha_panic_function flag);
 void ha_close_connection(THD* thd);
-enum db_type ha_checktype(enum db_type database_type);
+enum db_type ha_checktype(enum db_type database_type, bool no_substitute,
+                          bool report_error);
 my_bool ha_storage_engine_is_enabled(enum db_type database_type);
 int ha_create_table(const char *name, HA_CREATE_INFO *create_info,
 		    bool update_create_info);

--- 1.350/sql/mysql_priv.h	2005-06-04 06:23:30 +01:00
+++ 1.351/sql/mysql_priv.h	2005-06-06 17:33:18 +01:00
@@ -240,6 +240,7 @@
 #define MODE_MYSQL40                   (MODE_MYSQL323*2)
 #define MODE_ANSI	               (MODE_MYSQL40*2)
 #define MODE_NO_AUTO_VALUE_ON_ZERO     (MODE_ANSI*2)
+#define MODE_NO_ENGINE_SUBSTITUTION    (MODE_NO_AUTO_VALUE_ON_ZERO*2)
 
 #define RAID_BLOCK_SIZE 1024
 

--- 1.573/sql/mysqld.cc	2005-06-03 21:45:57 +01:00
+++ 1.574/sql/mysqld.cc	2005-06-06 17:33:18 +01:00
@@ -238,7 +238,7 @@
   "NO_DIR_IN_CREATE",
   "POSTGRESQL", "ORACLE", "MSSQL", "DB2", "MAXDB", "NO_KEY_OPTIONS",
   "NO_TABLE_OPTIONS", "NO_FIELD_OPTIONS", "MYSQL323", "MYSQL40", "ANSI",
-  "NO_AUTO_VALUE_ON_ZERO", NullS
+  "NO_AUTO_VALUE_ON_ZERO", "NO_ENGINE_SUBSTITUTION", NullS
 };
 TYPELIB sql_mode_typelib= { array_elements(sql_mode_names)-1,"",
 			    sql_mode_names, NULL };

--- 1.287/sql/sql_table.cc	2005-06-04 06:23:31 +01:00
+++ 1.288/sql/sql_table.cc	2005-06-06 17:33:19 +01:00
@@ -39,7 +39,9 @@
                                     bool ignore,
 				    uint order_num, ORDER *order,
 				    ha_rows *copied,ha_rows *deleted);
-
+static bool check_engine(THD *thd, const char *table_name,
+                         enum db_type *new_engine);
+                             
 
 /*
  Build the path to a file for a table (or the base path that can
@@ -1274,7 +1276,6 @@
   uint		db_options, key_count;
   KEY		*key_info_buffer;
   handler	*file;
-  enum db_type	new_db_type;
   DBUG_ENTER("mysql_create_table");
 
   /* Check for duplicate fields and check type of table to create */
@@ -1283,16 +1284,8 @@
     my_error(ER_TABLE_MUST_HAVE_COLUMNS,MYF(0));
     DBUG_RETURN(-1);
   }
-  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(-1)
   db_options=create_info->table_options;
   if (create_info->row_type == ROW_TYPE_DYNAMIC)
     db_options|=HA_OPTION_PACK_RECORD;
@@ -2832,16 +2825,9 @@
   old_db_type=table->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(1);
+  new_db_type= create_info->db_type;
   if (create_info->row_type == ROW_TYPE_NOT_USED)
     create_info->row_type=table->row_type;
 
@@ -3785,4 +3771,25 @@
   if (table)
     table->table=0;
   DBUG_RETURN(-1);
+}
+
+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= 
+        !!(thd->variables.sql_mode & MODE_NO_ENGINE_SUBSTITUTION);
+  if ((*new_engine= 
+       ha_checktype(req_engine, no_substitution, 1)) == DB_TYPE_UNKNOWN)
+    return 1;
+
+  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 0;
 }

--- 1.129/sql/table.cc	2005-05-18 18:40:35 +01:00
+++ 1.130/sql/table.cc	2005-06-06 17:33:19 +01:00
@@ -136,7 +136,7 @@
   *fn_ext(index_file)='\0';			// Remove .frm extension
 
   outparam->frm_version= head[2];
-  outparam->db_type=ha_checktype((enum db_type) (uint) *(head+3));
+  outparam->db_type=ha_checktype((enum db_type) (uint) *(head+3),1,0);
   outparam->db_create_options=db_create_options=uint2korr(head+30);
   outparam->db_options_in_use=outparam->db_create_options;
   null_field_first=0;
@@ -1267,7 +1267,7 @@
   {
     bzero((char*) fileinfo,64);
     fileinfo[0]=(uchar) 254; fileinfo[1]= 1; fileinfo[2]= FRM_VER+3; // Header
-    fileinfo[3]= (uchar) ha_checktype(create_info->db_type);
+    fileinfo[3]= (uchar) ha_checktype(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;
@@ -1533,7 +1533,7 @@
   if (error || head[0] != (uchar) 254 || head[1] != 1 ||
       (head[2] != FRM_VER && head[2] != FRM_VER+1 && head[2] != FRM_VER+3))
     DBUG_RETURN(DB_TYPE_UNKNOWN);
-  DBUG_RETURN(ha_checktype((enum db_type) (uint) *(head+3)));
+  DBUG_RETURN(ha_checktype((enum db_type) (uint) *(head+3),1,0));
 }
 
 

--- 1.10/mysql-test/r/sql_mode.result	2004-11-04 04:48:56 +00:00
+++ 1.11/mysql-test/r/sql_mode.result	2005-06-06 17:33:17 +01:00
@@ -138,3 +138,21 @@
   `min_num` decimal(7,6) default '0.000001'
 ) ENGINE=MyISAM DEFAULT CHARSET=latin1
 drop table t1 ;
+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;

--- 1.7/mysql-test/t/sql_mode.test	2004-11-04 04:47:51 +00:00
+++ 1.8/mysql-test/t/sql_mode.test	2005-06-06 17:33:17 +01:00
@@ -80,3 +80,21 @@
 show create table t1;
 drop table t1 ;
 
+#
+# 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;
+

--- 1.169/sql/set_var.cc	2005-06-05 18:38:41 +01:00
+++ 1.170/sql/set_var.cc	2005-06-06 17:33:19 +01:00
@@ -2987,7 +2987,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(db_type,1,0) != db_type)
     {
       value= res ? res->c_ptr() : "NULL";
       goto err;
Thread
bk commit into 4.1 tree (acurtis:1.2316) BUG#6877antony6 Jun