List:Commits« Previous MessageNext Message »
From:jani Date:March 19 2007 9:19am
Subject:bk commit into 5.1 tree (jani:1.2481)
View as plain text  
Below is the list of changes that have just been committed into a local
5.1 repository of jani. When jani 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@stripped, 2007-03-19 11:19:51+02:00, jani@stripped +12 -0
  Added find_type_or_exit and find_bit_type_or_exit as wrappers
  around the original functions. These will ensure that error
  message is always in unique form, reduce code and print the
  right alternatives automatically in an error case.

  client/mysql.cc@stripped, 2007-03-19 11:19:46+02:00, jani@stripped +2 -7
    Changed find_type to find_type_or_exit

  client/mysqladmin.cc@stripped, 2007-03-19 11:19:46+02:00, jani@stripped +2 -7
    Changed find_type to find_type_or_exit

  client/mysqlbinlog.cc@stripped, 2007-03-19 11:19:46+02:00, jani@stripped +2 -7
    Changed find_type to find_type_or_exit

  client/mysqlcheck.c@stripped, 2007-03-19 11:19:46+02:00, jani@stripped +2 -7
    Changed find_type to find_type_or_exit

  client/mysqldump.c@stripped, 2007-03-19 11:19:46+02:00, jani@stripped +3 -8
    Changed find_type to find_type_or_exit

  client/mysqlimport.c@stripped, 2007-03-19 11:19:47+02:00, jani@stripped +2 -7
    Changed find_type to find_type_or_exit

  client/mysqlshow.c@stripped, 2007-03-19 11:19:47+02:00, jani@stripped +2 -7
    Changed find_type to find_type_or_exit

  client/mysqlslap.c@stripped, 2007-03-19 11:19:47+02:00, jani@stripped +3 -8
    Changed find_type to find_type_or_exit

  include/typelib.h@stripped, 2007-03-19 11:19:47+02:00, jani@stripped +2 -0
    Added find_type_or_exit

  mysql-test/r/mysql_protocols.result@stripped, 2007-03-19 11:19:47+02:00, jani@stripped +1 -0
    Fixed result.

  mysys/typelib.c@stripped, 2007-03-19 11:19:47+02:00, jani@stripped +22 -0
    Added find_type_or_exit

  sql/mysqld.cc@stripped, 2007-03-19 11:19:47+02:00, jani@stripped +46 -72
    Added use of find_type_or_exit and find_bit_type_or_exit
    Fixed a missing break; from an option handling. (Bug
    in --tc-heuristic-recover)

# 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:	jani
# Host:	ua141d10.elisa.omakaista.fi
# Root:	/home/my/bk/mysql-5.1-marvel

--- 1.255/client/mysql.cc	2007-03-19 11:19:59 +02:00
+++ 1.256/client/mysql.cc	2007-03-19 11:19:59 +02:00
@@ -885,14 +885,9 @@
     opt_nopager= 1;
     break;
   case OPT_MYSQL_PROTOCOL:
-  {
-    if ((opt_protocol= find_type(argument, &sql_protocol_typelib,0)) <= 0)
-    {
-      fprintf(stderr, "Unknown option to protocol: %s\n", argument);
-      exit(1);
-    }
+    opt_protocol= find_type_or_exit(argument, &sql_protocol_typelib,
+                                    opt->name);
     break;
-  }
   break;
   case 'A':
     opt_rehash= 0;

--- 1.118/client/mysqladmin.cc	2007-03-19 11:19:59 +02:00
+++ 1.119/client/mysqladmin.cc	2007-03-19 11:19:59 +02:00
@@ -284,14 +284,9 @@
 #endif
     break;
   case OPT_MYSQL_PROTOCOL:
-  {
-    if ((opt_protocol= find_type(argument, &sql_protocol_typelib,0)) <= 0)
-    {
-      fprintf(stderr, "Unknown option to protocol: %s\n", argument);
-      exit(1);
-    }
+    opt_protocol= find_type_or_exit(argument, &sql_protocol_typelib,
+                                    opt->name);
     break;
-  }
   }
   if (error)
   {

--- 1.268/client/mysqldump.c	2007-03-19 11:19:59 +02:00
+++ 1.269/client/mysqldump.c	2007-03-19 11:19:59 +02:00
@@ -790,14 +790,9 @@
       break;
     }
   case (int) OPT_MYSQL_PROTOCOL:
-    {
-      if ((opt_protocol= find_type(argument, &sql_protocol_typelib,0)) <= 0)
-      {
-        fprintf(stderr, "Unknown option to protocol: %s\n", argument);
-        exit(1);
-      }
-      break;
-    }
+    opt_protocol= find_type_or_exit(argument, &sql_protocol_typelib,
+                                    opt->name);
+    break;
   }
   return 0;
 }

--- 1.81/client/mysqlimport.c	2007-03-19 11:19:59 +02:00
+++ 1.82/client/mysqlimport.c	2007-03-19 11:19:59 +02:00
@@ -231,14 +231,9 @@
     break;
 #endif
   case OPT_MYSQL_PROTOCOL:
-  {
-    if ((opt_protocol= find_type(argument, &sql_protocol_typelib,0)) <= 0)
-    {
-      fprintf(stderr, "Unknown option to protocol: %s\n", argument);
-      exit(1);
-    }
+    opt_protocol= find_type_or_exit(argument, &sql_protocol_typelib,
+                                    opt->name);
     break;
-  }
   case '#':
     DBUG_PUSH(argument ? argument : "d:t:o");
     break;

--- 1.52/client/mysqlshow.c	2007-03-19 11:19:59 +02:00
+++ 1.53/client/mysqlshow.c	2007-03-19 11:19:59 +02:00
@@ -287,14 +287,9 @@
 #endif
     break;
   case OPT_MYSQL_PROTOCOL:
-  {
-    if ((opt_protocol= find_type(argument, &sql_protocol_typelib,0)) <= 0)
-    {
-      fprintf(stderr, "Unknown option to protocol: %s\n", argument);
-      exit(1);
-    }
+    opt_protocol= find_type_or_exit(argument, &sql_protocol_typelib,
+                                    opt->name);
     break;
-  }
   case '#':
     DBUG_PUSH(argument ? argument : "d:t:o");
     break;

--- 1.18/mysys/typelib.c	2007-03-19 11:19:59 +02:00
+++ 1.19/mysys/typelib.c	2007-03-19 11:19:59 +02:00
@@ -20,6 +20,28 @@
 #include <m_ctype.h>
 
 
+int find_type_or_exit(const char *x, TYPELIB *typelib, const char *option)
+{
+  int res;
+  const char **ptr;
+
+  if ((res= find_type((my_string) x, typelib, 2)) <= 0)
+  {
+    ptr= typelib->type_names;
+    if (!*x)
+      fprintf(stderr, "No option given to %s\n", option);
+    else
+      fprintf(stderr, "Unknown option to %s: %s\n", option, x);
+    fprintf(stderr, "Alternatives are: '%s'", *ptr);
+    while (*++ptr)
+      fprintf(stderr, ",'%s'", *ptr);
+    fprintf(stderr, "\n");
+    exit(1);
+  }
+  return res;
+}
+
+
 /*
   Search after a string in a list of strings. Endspace in x is not compared.
 

--- 1.149/client/mysqlbinlog.cc	2007-03-19 11:19:59 +02:00
+++ 1.150/client/mysqlbinlog.cc	2007-03-19 11:19:59 +02:00
@@ -948,14 +948,9 @@
     remote_opt= 1;
     break;
   case OPT_MYSQL_PROTOCOL:
-  {
-    if ((opt_protocol= find_type(argument, &sql_protocol_typelib,0)) <= 0)
-    {
-      fprintf(stderr, "Unknown option to protocol: %s\n", argument);
-      exit(1);
-    }
+    opt_protocol= find_type_or_exit(argument, &sql_protocol_typelib,
+                                    opt->name);
     break;
-  }
   case OPT_START_DATETIME:
     start_datetime= convert_str_to_timestamp(start_datetime_str);
     break;

--- 1.619/sql/mysqld.cc	2007-03-19 11:19:59 +02:00
+++ 1.620/sql/mysqld.cc	2007-03-19 11:19:59 +02:00
@@ -737,6 +737,8 @@
 #endif
 pthread_handler_t handle_slave(void *arg);
 static ulong find_bit_type(const char *x, TYPELIB *bit_lib);
+static ulong find_bit_type_or_exit(const char *x, TYPELIB *bit_lib,
+                                   const char *option);
 static void clean_up(bool print_message);
 static int test_if_case_insensitive(const char *dir_name);
 
@@ -7411,11 +7413,7 @@
   case (int) OPT_INIT_RPL_ROLE:
   {
     int role;
-    if ((role=find_type(argument, &rpl_role_typelib, 2)) <= 0)
-    {
-      fprintf(stderr, "Unknown replication role: %s\n", argument);
-      exit(1);
-    }
+    role= find_type_or_exit(argument, &rpl_role_typelib, opt->name);
     rpl_status = (role == 1) ?  RPL_AUTH_MASTER : RPL_IDLE_SLAVE;
     break;
   }
@@ -7471,17 +7469,7 @@
   case OPT_BINLOG_FORMAT:
   {
     int id;
-    if ((id= find_type(argument, &binlog_format_typelib, 2)) <= 0)
-    {
-      fprintf(stderr, 
-	      "Unknown binary log format: '%s' "
-	      "(should be one of '%s', '%s', '%s')\n", 
-	      argument,
-              binlog_format_names[BINLOG_FORMAT_STMT],
-              binlog_format_names[BINLOG_FORMAT_ROW],
-              binlog_format_names[BINLOG_FORMAT_MIXED]);
-      exit(1);
-    }
+    id= find_type_or_exit(argument, &binlog_format_typelib, opt->name);
     global_system_variables.binlog_format= opt_binlog_format_id= id - 1;
     break;
   }
@@ -7541,13 +7529,9 @@
     else
     {
       log_output_str= argument;
-      if ((log_output_options=
-           find_bit_type(argument, &log_output_typelib)) == ~(ulong) 0)
-      {
-        fprintf(stderr, "Unknown option to log-output: %s\n", argument);
-        exit(1);
-      }
-    }
+      log_output_options=
+        find_bit_type_or_exit(argument, &log_output_typelib, opt->name);
+  }
     break;
   }
 #endif
@@ -7561,10 +7545,8 @@
         type=     5          1   2      3   4
              (DISABLE ) - (OFF | ON) - (0 | 1)
       */
-      switch ((type=find_type(argument, &Events::opt_typelib, 1))) {
-      case 0:
-	fprintf(stderr, "Unknown option to event-scheduler: %s\n",argument);
-	exit(1);
+      type= find_type_or_exit(argument, &Events::opt_typelib, opt->name);
+      switch (type) {
       case 5: /* OPT_DISABLED */
         Events::opt_event_scheduler= Events::EVENTS_DISABLED;
         break;
@@ -7714,11 +7696,7 @@
     else
     {
       int type;
-      if ((type=find_type(argument, &delay_key_write_typelib, 2)) <= 0)
-      {
-	fprintf(stderr,"Unknown delay_key_write type: %s\n",argument);
-	exit(1);
-      }
+      type= find_type_or_exit(argument, &delay_key_write_typelib, opt->name);
       delay_key_write_options= (uint) type-1;
     }
     break;
@@ -7729,11 +7707,7 @@
   case OPT_TX_ISOLATION:
   {
     int type;
-    if ((type=find_type(argument, &tx_isolation_typelib, 2)) <= 0)
-    {
-      fprintf(stderr,"Unknown transaction isolation type: %s\n",argument);
-      exit(1);
-    }
+    type= find_type_or_exit(argument, &tx_isolation_typelib, opt->name);
     global_system_variables.tx_isolation= (type-1);
     break;
   }
@@ -7774,16 +7748,7 @@
     break;
   case OPT_NDB_DISTRIBUTION:
     int id;
-    if ((id= find_type(argument, &ndb_distribution_typelib, 2)) <= 0)
-    {
-      fprintf(stderr, 
-	      "Unknown ndb distribution type: '%s' "
-	      "(should be '%s' or '%s')\n", 
-	      argument,
-              ndb_distribution_names[ND_KEYHASH],
-              ndb_distribution_names[ND_LINHASH]);
-      exit(1);
-    }
+    id= find_type_or_exit(argument, &ndb_distribution_typelib, opt->name);
     opt_ndb_distribution_id= (enum ndb_distribution)(id-1);
     break;
   case OPT_NDB_EXTRA_LOGGING:
@@ -7823,12 +7788,8 @@
     else
     {
       myisam_recover_options_str=argument;
-      if ((myisam_recover_options=
-	   find_bit_type(argument, &myisam_recover_typelib)) == ~(ulong) 0)
-      {
-	fprintf(stderr, "Unknown option to myisam-recover: %s\n",argument);
-	exit(1);
-      }
+      myisam_recover_options=
+        find_bit_type_or_exit(argument, &myisam_recover_typelib, opt->name);
     }
     ha_open_options|=HA_OPEN_ABORT_IF_CRASHED;
     break;
@@ -7841,14 +7802,10 @@
       myisam_concurrent_insert= 0;      /* --skip-concurrent-insert */
     break;
   case OPT_TC_HEURISTIC_RECOVER:
-  {
-    if ((tc_heuristic_recover=find_type(argument,
-                                        &tc_heuristic_recover_typelib, 2)) <=0)
-    {
-      fprintf(stderr, "Unknown option to tc-heuristic-recover: %s\n",argument);
-      exit(1);
-    }
-  }
+    tc_heuristic_recover= find_type_or_exit(argument,
+                                            &tc_heuristic_recover_typelib,
+                                            opt->name);
+    break;
   case OPT_MYISAM_STATS_METHOD:
   {
     ulong method_conv;
@@ -7856,11 +7813,8 @@
     LINT_INIT(method_conv);
 
     myisam_stats_method_str= argument;
-    if ((method=find_type(argument, &myisam_stats_method_typelib, 2)) <= 0)
-    {
-      fprintf(stderr, "Invalid value of myisam_stats_method: %s.\n", argument);
-      exit(1);
-    }
+    method= find_type_or_exit(argument, &myisam_stats_method_typelib,
+                              opt->name);
     switch (method-1) {
     case 2:
       method_conv= MI_STATS_METHOD_IGNORE_NULLS;
@@ -7879,12 +7833,8 @@
   case OPT_SQL_MODE:
   {
     sql_mode_str= argument;
-    if ((global_system_variables.sql_mode=
-         find_bit_type(argument, &sql_mode_typelib)) == ~(ulong) 0)
-    {
-      fprintf(stderr, "Unknown option to sql-mode: %s\n", argument);
-      exit(1);
-    }
+    global_system_variables.sql_mode=
+      find_bit_type_or_exit(argument, &sql_mode_typelib, opt->name);
     global_system_variables.sql_mode= fix_sql_mode(global_system_variables.
 						   sql_mode);
     break;
@@ -8189,6 +8139,30 @@
     my_free(opt_secure_file_priv, MYF(0));
     opt_secure_file_priv= my_strdup(buff, MYF(MY_FAE));
   }
+}
+
+
+static ulong find_bit_type_or_exit(const char *x, TYPELIB *bit_lib,
+                                   const char *option)
+{
+  ulong res;
+
+  const char **ptr;
+  
+  if ((res= find_bit_type(x, bit_lib)) == ~(ulong) 0)
+  {
+    ptr= bit_lib->type_names;
+    if (!*x)
+      fprintf(stderr, "No option given to %s\n", option);
+    else
+      fprintf(stderr, "Wrong option to %s. Option(s) given: %s\n", option, x);
+    fprintf(stderr, "Alternatives are: '%s'", *ptr);
+    while (*++ptr)
+      fprintf(stderr, ",'%s'", *ptr);
+    fprintf(stderr, "\n");
+    exit(1);
+  }
+  return res;
 }
 
 

--- 1.61/client/mysqlcheck.c	2007-03-19 11:19:59 +02:00
+++ 1.62/client/mysqlcheck.c	2007-03-19 11:19:59 +02:00
@@ -310,14 +310,9 @@
     break;
   case 'V': print_version(); exit(0);
   case OPT_MYSQL_PROTOCOL:
-  {
-    if ((opt_protocol= find_type(argument, &sql_protocol_typelib,0)) <= 0)
-    {
-      fprintf(stderr, "Unknown option to protocol: %s\n", argument);
-      exit(1);
-    }
+    opt_protocol= find_type_or_exit(argument, &sql_protocol_typelib,
+                                    opt->name);
     break;
-  }
   }
   return 0;
 }

--- 1.6/include/typelib.h	2007-03-19 11:19:59 +02:00
+++ 1.7/include/typelib.h	2007-03-19 11:19:59 +02:00
@@ -26,6 +26,8 @@
   unsigned int *type_lengths;
 } TYPELIB;
 
+extern int find_type_or_exit(const char *x, TYPELIB *typelib,
+                             const char *option);
 extern int find_type(char *x,TYPELIB *typelib,unsigned int full_name);
 extern void make_type(char *to,unsigned int nr,TYPELIB *typelib);
 extern const char *get_type(TYPELIB *typelib,unsigned int nr);

--- 1.42/client/mysqlslap.c	2007-03-19 11:19:59 +02:00
+++ 1.43/client/mysqlslap.c	2007-03-19 11:19:59 +02:00
@@ -568,14 +568,9 @@
 #endif
     break;
   case OPT_MYSQL_PROTOCOL:
-    {
-      if ((opt_protocol= find_type(argument, &sql_protocol_typelib,0)) <= 0)
-      {
-        fprintf(stderr, "Unknown option to protocol: %s\n", argument);
-        exit(1);
-      }
-      break;
-    }
+    opt_protocol= find_type_or_exit(argument, &sql_protocol_typelib,
+                                    opt->name);
+    break;
   case '#':
     DBUG_PUSH(argument ? argument : default_dbug_option);
     break;

--- 1.2/mysql-test/r/mysql_protocols.result	2007-03-19 11:19:59 +02:00
+++ 1.3/mysql-test/r/mysql_protocols.result	2007-03-19 11:19:59 +02:00
@@ -7,3 +7,4 @@
 ERROR 2047 (HY000): Wrong or unknown protocol
 ERROR 2047 (HY000): Wrong or unknown protocol
 Unknown option to protocol: NullS
+Alternatives are: 'TCP','SOCKET','PIPE','MEMORY'
Thread
bk commit into 5.1 tree (jani:1.2481)jani19 Mar