From 71c7035035b8cfeb6f28cd058dd67116bfd9ed33 Mon Sep 17 00:00:00 2001 From: "jani@ua141d10.elisa.omakaista.fi" <> Date: Mon, 19 Mar 2007 11:19:51 +0200 Subject: 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 | 9 ++------- client/mysqladmin.cc | 9 ++------- client/mysqlbinlog.cc | 9 ++------- client/mysqlcheck.c | 9 ++------- client/mysqldump.c | 11 +++-------- client/mysqlimport.c | 9 ++------- client/mysqlshow.c | 9 ++------- client/mysqlslap.c | 11 +++-------- 8 files changed, 18 insertions(+), 58 deletions(-) (limited to 'client') diff --git a/client/mysql.cc b/client/mysql.cc index 48172d97f56..c13fb958a1a 100644 --- a/client/mysql.cc +++ b/client/mysql.cc @@ -885,14 +885,9 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)), 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; diff --git a/client/mysqladmin.cc b/client/mysqladmin.cc index ccfff4d7a03..4670cb98caf 100644 --- a/client/mysqladmin.cc +++ b/client/mysqladmin.cc @@ -284,15 +284,10 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)), #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) { usage(); diff --git a/client/mysqlbinlog.cc b/client/mysqlbinlog.cc index 940fac6da38..a0a7572d92e 100644 --- a/client/mysqlbinlog.cc +++ b/client/mysqlbinlog.cc @@ -948,14 +948,9 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)), 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; diff --git a/client/mysqlcheck.c b/client/mysqlcheck.c index 1a9d07804b4..41c5cde4023 100644 --- a/client/mysqlcheck.c +++ b/client/mysqlcheck.c @@ -310,15 +310,10 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)), 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; } diff --git a/client/mysqldump.c b/client/mysqldump.c index 5f2749eef77..4a6c9e64151 100644 --- a/client/mysqldump.c +++ b/client/mysqldump.c @@ -790,14 +790,9 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)), 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; } diff --git a/client/mysqlimport.c b/client/mysqlimport.c index 3e054fba308..c037da9c0b9 100644 --- a/client/mysqlimport.c +++ b/client/mysqlimport.c @@ -231,14 +231,9 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)), 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; diff --git a/client/mysqlshow.c b/client/mysqlshow.c index 1c714cc640f..0c6a6229964 100644 --- a/client/mysqlshow.c +++ b/client/mysqlshow.c @@ -287,14 +287,9 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)), #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; diff --git a/client/mysqlslap.c b/client/mysqlslap.c index ad2c8685ba1..d673f8f6f81 100644 --- a/client/mysqlslap.c +++ b/client/mysqlslap.c @@ -568,14 +568,9 @@ get_one_option(int optid, const struct my_option *opt __attribute__((unused)), #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; -- cgit v1.2.1 From 7c638268948dae63be1a9eb3aa83da040e028aba Mon Sep 17 00:00:00 2001 From: "tnurnberg@sin.intern.azundris.com" <> Date: Fri, 23 Mar 2007 19:24:03 +0100 Subject: Bug #26817: mysqldump fails to backup database containing view with invalid definer give some leeway on required permissions for SHOW FIELDS on views so an unknonwn DEFINER will no longer break mysqldump --- client/client_priv.h | 2 +- client/mysqldump.c | 24 ++++++++++++++++++++++-- 2 files changed, 23 insertions(+), 3 deletions(-) (limited to 'client') diff --git a/client/client_priv.h b/client/client_priv.h index 7748dc612d6..418bf86f2c8 100644 --- a/client/client_priv.h +++ b/client/client_priv.h @@ -51,5 +51,5 @@ enum options_client OPT_TRIGGERS, OPT_IGNORE_TABLE,OPT_INSERT_IGNORE,OPT_SHOW_WARNINGS,OPT_DROP_DATABASE, OPT_TZ_UTC, OPT_AUTO_CLOSE, OPT_SSL_VERIFY_SERVER_CERT, - OPT_DEBUG_INFO + OPT_DEBUG_INFO, OPT_ERROR_LOG_FILE }; diff --git a/client/mysqldump.c b/client/mysqldump.c index 94ab9dac5ac..0d7c0c3a0bf 100644 --- a/client/mysqldump.c +++ b/client/mysqldump.c @@ -105,7 +105,8 @@ static char *opt_password=0,*current_user=0, *lines_terminated=0, *enclosed=0, *opt_enclosed=0, *escaped=0, *where=0, *order_by=0, *opt_compatible_mode_str= 0, - *err_ptr= 0; + *err_ptr= 0, + *log_error_file= NULL; static char **defaults_argv= 0; static char compatible_mode_normal_str[255]; static ulong opt_compatible_mode= 0; @@ -116,7 +117,9 @@ static my_string opt_mysql_unix_port=0; static int first_error=0; static DYNAMIC_STRING extended_row; #include -FILE *md_result_file= 0; +FILE *md_result_file= 0; +FILE *stderror_file=0; + #ifdef HAVE_SMEM static char *shared_memory_base_name=0; #endif @@ -293,6 +296,9 @@ static struct my_option my_long_options[] = 0, 0, 0, 0, 0, 0}, {"lock-tables", 'l', "Lock all tables for read.", (gptr*) &lock_tables, (gptr*) &lock_tables, 0, GET_BOOL, NO_ARG, 1, 0, 0, 0, 0, 0}, + {"log-error", OPT_ERROR_LOG_FILE, "Append warnings and errors to given file.", + (gptr*) &log_error_file, (gptr*) &log_error_file, 0, GET_STR, + REQUIRED_ARG, 0, 0, 0, 0, 0, 0}, {"master-data", OPT_MASTER_DATA, "This causes the binary log position and filename to be appended to the " "output. If equal to 1, will print it as a CHANGE MASTER command; if equal" @@ -3694,6 +3700,16 @@ int main(int argc, char **argv) free_resources(0); exit(exit_code); } + + if (log_error_file) + { + if(!(stderror_file= freopen(log_error_file, "a+", stderr))) + { + free_resources(0); + exit(EX_MYSQLERR); + } + } + if (connect_to_db(current_host, current_user, opt_password)) { free_resources(0); @@ -3746,5 +3762,9 @@ err: if (!path) write_footer(md_result_file); free_resources(); + + if (stderror_file) + fclose(stderror_file); + return(first_error); } /* main */ -- cgit v1.2.1